javascript - Not this selector on next element in jQuery chain -



javascript - Not this selector on next element in jQuery chain -

i'm having chain of jquery methods find ul in li , animate height of it.

$('.collapse-trigger').click(function() { if($(this).next('.collapse-ul').height() == 0) { $(this).css('background', '#000000'); var height = $(this).next('.collapse-ul').children().length; $(this).next('.collapse-ul').animate({height: height*42}, 500); // multiply height number of menupoints } else { $(this).css('background', '#414141'); $(this).next('.collapse-ul').animate({height: 0}, 500); } });

with can collapse each ul , on click 1 time again animates 0. intend is, when 1 of ul animating out, others animate zero.

i assume need .not(this) struggle it. attempt:

$('this').next().not('.collapse-ul', this).animate({height: 0}, 500); // <-- within not method don't know how write

thanks

try : can find collapsible ul first , filter using .not()

$('.collapse-trigger').click(function() { if($(this).next('.collapse-ul').height() == 0) { $(this).css('background', '#000000'); var height = $(this).next('.collapse-ul').children().length; var $collapseul = $(this).next('.collapse-ul'); //filter current collapsible ul $('.collapse-ul').not($collapseul).animate({height: 0}, 500); $collapseul.animate({height: height*42}, 500); // multiply height number of menupoints } else { $(this).css('background', '#414141'); $(this).next('.collapse-ul').animate({height: 0}, 500); } });

javascript jquery html chain

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -