jquery - Check if has class -
this html:
<div id="gallery"> <div class="item"></div> <div class="somethingelse"></div> <div class="item"></div> <div class="somethingelse"></div> <div class="item active"></div> <div class="somethingelse"></div> <div class="item"></div> </div>
now, each item
want add number in div, did this:
function initmenu() { $( ".gallery-menu" ).html(""); var columns = $('.item').length; ( var = 0; < columns; i++ ) { $( ".gallery-menu" ).append( ); } } initmenu();
now simple 0 1 2 3
in gallery-menu
div good.
now want check if active
. added check this:
function initmenu() { $( ".gallery-menu" ).html(""); var columns = $('.item').length; ( var = 0; < columns; i++ ) { if ($(".item:eq(i)").hasclass('active')) { $( ".gallery-menu" ).append( + "-active"); } else { $( ".gallery-menu" ).append( ); } } } initmenu();
but it's not working.. able point me in right direction?
a cleaner way use jquery's each()
function:
$('.item').each(function(i, el){ if ($(this).hasclass('active')) { $( ".gallery-menu" ).append( + "-active"); } else { $( ".gallery-menu" ).append( ); } });
Comments
Post a Comment