How would I write a jquery action so that when anything on a web page is clicked EXCEPT a certain div, then the query performs a function?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s my way:
http://jsfiddle.net/v3N2T/5/
The idea is that you put the click event on the whole page and then catch the click on the element you don’t want to do the action and prevent it from propogating the click event up to the document click event.
It might interact badly if you have any other click event stuff going on but you may have that problem anyway…
P.S. Credit to Adrian for his original answer that allowed me to develop this solution much more quickly by just modifying his. 🙂