i wrote this function to toggle a class name, of next div using jquery chaining function, but it doen't work...
$('a.back-btn,a.front-btn').click(function(e){
e.preventDefault();
$(this).toggleClass('back-btn front-btn').end()
.next().find('.models').toggleClass('rotated');
})
in case if i write separate line, then it works fine :
$('a.back-btn,a.front-btn').click(function(e){
e.preventDefault();
$(this).toggleClass('back-btn front-btn');
$(this).next('.models').toggleClass('rotated'); // separate line
})
what is the issue with my chaining function, how it need to end a process in case if i use the chaining. i used end(), is it wrong? any best clarification to use end()?
thanks in advance
$(this).next('.models')returns the element afterthisif it has the classmodels.$(this).next().find('.models')returns all elements that have the classmodelsand are descendents of the element afterthis. Honestly, I'm not entirely convinced that the.end()was the only issue, and rather you were writing code that wasn't what you actually meant or wanted..end()should clear things up. The.end()is not needed and is messing things up.