I’ve build a site that has accordion sections that expand whenever someone clicks on the header section for that page, the click handler is placed on
$('.section h2').click
However, when a user is logged in as admin, there are ‘EDIT’ links applied to the header, so I only want the section to expand if the area clicked is not “a.edit-link”.
I’ve tried things like $('.section h2:not(a.edit-link)').click… or $('.section h2').not('a.edit-link').click, but niether of these options are working for me..
Am I missing out on something obvious?
You can do it using
event.stopPropagation(), like this:When a click on an
a.edit-linkhappens, that click just won’t bubble up to the<h2>parent, and itsclickhandler won’t fire.Alternatively you could check the event target inside your handler, like this: