Avoid double events (onclick) with nested ul / li

I have a two-level ul / li menu in which li can fire different onclick events.

It seems that the parent event (ul li) is fired when you click on one element ul li ul. item.

Can I avoid this in a simple way.

(I'm considering using a timer to capture the second event, but I think this is an ugly fix ...)

Regards, / T

+6
javascript html css
source share
2 answers

I assume you need to stop the event bubble so if you use direct javascript you have event.cancelBubble = true

otherwise if you use jQuery you have event.stopPropagation() or event.stopImmediatePropagation()

http://api.jquery.com/category/events/event-object/

+8
source share

I found the right word to search on Google and got an answer. Perhaps this is what you are looking for.

Javascript event propagation

+2
source share

All Articles