we're showing a box on the screen that I want to hide when the user clicks anywhere on the screen, including body, anchors, divs, buttons, etc... Is there a selector that can handle this for me? Or is it a case of $('body, a, div, input').click()
?
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
You can do it like this:
Since the
click
events will, by default, bubble up todocument
, this is a "catch all" approach...if you don't want clicks from inside the box to close it, add a.stopPropagation()
call on thoseclick
events like this:You can just bind to the click event of document element. Try it at http://jsfiddle.net/ZqEbY/.