I have the following jQuery:
$('.io-sidebar-section').click(function () {
console.log('Section Clicked');
$(this).next().fadeToggle('fast',function(){});
});
$('.io-sidebar-section-advanced-toggle').click(function(){
$(this).parent().next().children('.io-sidebar-link-advanced').fadeToggle('fast',function(){});
});
the advanced toggle is inside of a sidebar section. When I click on the advanced toggle, it executes the sidebar section click.
How can I seperate these two out?
You can use the
stopPropagationmethod of the event object inside theclickevent handler for the child element:From the jQuery docs, here’s what
stopPropagationdoes:As mentioned in the comments, if you prefer you can alternatively use
return falsein the event handler (in this particular case, as far as I can tell anyway – it will also causepreventDefaultwhich may not be what you want to happen). My personal preference is to usestopPropagationbut it’s completely up to you.