jQuery find li elements until, if has nextUntil elements


/ Published in: jQuery
Save to your folder(s)

Catches click, if element has nextUntil elements, triggers a slideDown of child elements and returns false (to stop the anchor), if there are no nextUntil elements, does nothing and allows the click through (the anchor works).


Copy this code and paste it in your HTML
  1. $("li.par_cat").click(function() {
  2. var el_count = $(this).nextUntil("li.par_cat").size();
  3. if(el_count == 0){
  4. // I'll add something here later.
  5. }else{
  6. $(this).nextUntil("li.par_cat").each(function() {
  7. $(this).slideToggle("slow");
  8. });
  9. return false;
  10. }
  11. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.