Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  32] [ 6]  / answers: 1 / hits: 7182  / 4 Years ago, sat, october 3, 2020, 12:00:00

How can I change ten on desktop to three on mobile with JS or jQuery or SemanticUI?


<div class="ui ten column grid">...</div>

If screen size is less than 700px, change ten to three.


More From » html

 Answers
0

You could use $(window).width() < 700 and check if width < 700 then removeClass ten and addClass three.


This function will run even if you resize you window manually via mouse.


//Resize window
function resize() {
if ($(window).width() < 700) {
$('.myDiv').removeClass('ten').addClass('three');
}
}

Runable Example:




//Resize window
function resize() {
if ($(window).width() < 700) {
$('.myDiv').removeClass('ten').addClass('three');
}
}

//watch window resize
$(window).on('resize', function() {
resize()
});

.ten {
background: green;
}

.three {
background: red;
}

<script src=https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js></script>
<div class=ui ten column grid myDiv>My Div</div>




[#2562] Tuesday, September 29, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kamronr

Total Points: 749
Total Questions: 110
Total Answers: 122

Location: Dominica
Member since Sat, Nov 5, 2022
2 Years ago
kamronr questions
Mon, Dec 21, 20, 00:00, 3 Years ago
Fri, Oct 16, 20, 00:00, 4 Years ago
Sun, Jul 28, 19, 00:00, 5 Years ago
Mon, Mar 18, 19, 00:00, 5 Years ago
;