A
A
Alexey Chertok2015-09-21 11:42:50
JavaScript
Alexey Chertok, 2015-09-21 11:42:50

How to correctly clean up the number of blocks and apply the value in jQuery?

Good afternoon. Guys, we need help.

In general, there is a footer, it has a menu. It's built like this:

<div class="downMenu">
    <ul class="reset">
        <li></li>
    </ul>
    <ul class="reset">
        <li></li>
    </ul>
    <ul class="reset">
        <li></li>
    </ul>
</div>


It is necessary to count the number of UI blocks, and if the value of these blocks is less than 4x, then assign the class to UL, and if more than 4he, then remove the class. Help, not very strong in jQuery.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
lyeskin, 2015-09-21
@BarnyBroken

if ( $('.downMenu > ul').length < 4) {
    $('.downMenu > ul').each(function() { $(this).addClass('SOMECLASS'); });
} else {
    $('.downMenu > ul').each(function() { $(this).removeClass('SOMECLASS'); });
}

A
Alexey Ukolov, 2015-09-21
@alexey-m-ukolov

jsfiddle.net/koceg/2vLsmbnu

$resets = $('.downMenu').find('.reset');
$resets.toggleClass('some-class', $resets.length < 4);

G
Gregory, 2015-09-21
@grigruss

var cnt = $('ul').length;
if(cnt<4){$('ul').addClass('ul-class-example');}
else{$('ul').removeClass('ul-class-example');}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question