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
The
end()function ends a child selection.You shouldn’t use it here.
end()would be used like this: