I need to make all the elements of a page, when clicked, execute a function, but at the same time I need to exclude a specific element including its child elements, since when clicked they should not execute the aforementioned function.
I need to make all the elements of a page, when clicked, execute a function, but at the same time I need to exclude a specific element including its child elements, since when clicked they should not execute the aforementioned function.
You could do this by raising an event for the entire DOM and then overriding clicks on the element in question using
event.stopPropagation()
.If you notice, in any element that is outside the div
#noHagasNada
a message will appear if you click. However, it won't do anything if you click on the div#noHagasNada
or any of its child elements.You can use the :not() selector like this:
You specify the element that you do not want to be included.