javascript - .next() jquery function skips next sibling -


i trying remove class element , add class next element. problem next element gets skipped. here javascript:

var $active = this.$view.find('.active'); if ($active.index() !== this.$view.children().length - 1) {     $active.next('.list-group-item').addclass('active');     $active.removeclass('active'); } 

here html:

 <div>      <a class="list-group-item active">1</a>      <a class="list-group-item active">2</a>      <a class="list-group-item active">3</a>      <a class="list-group-item active">4</a>  </div> 

$('.list-group-item').on('click',function(){      debugger;      var $active = $(this).parent().find('.active');      if ($active.index() !== $(this).parent().children().length - 1) {          $active.next('.list-group-item').addclass('active');          $active.removeclass('active');      }  });
.active{      font-weight:bolder;  }
<div>       <a class="list-group-item active">1</a>       <a class="list-group-item ">2</a>       <a class="list-group-item ">3</a>       <a class="list-group-item ">4</a>  </div>

hi think trying achieve understand code

here jsfiddle

jsfiddle

points first

  • .active class given tags.
  • then after finding tag's children element never coz it's not having.

i have corrected desired code way change prospective work


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -