I want to make an event listener that triggers some code when a certain element is clicked, and one that toggles some code if anything but that element is clicked. So far, all I’ve come up with is making two handlers, one for the body and one for the element, and slightly delaying the code with setTimeout() to avoid the two handlers conflicting. It looks very ugly and, well, not right. Is there a better way to do what I need here? Or, is there an "all-but-this-element" handler I can use? I have been doing this with jQuery, so answers dependent on the library are welcome and preferred.
I want to make an event listener that triggers some code when a certain
Share
If you want to bind the click to all elements not to an element with id “div1”, you can use like: