I have a div inside a user control that is displayed by the user after some event.
I want to hide this div when user clicks anywhere elese on the page but not on the div (or not on any element that is inside the div).If it wasn't a user control I could use body's clieck event to check the target, but because this is usercontrol that is hosted b开发者_StackOverflow中文版y other page I can't just "play" with it's elements.
How can I achieve that without using body of the hosting page?
You certainly can't. But it doesn't matter, because you won't overwrite any existing event handler if you use the addEventListener
/attachEvent
method instead of the document.body.onclick="..."
method.
Here is an example using the Prototype library for easier coding: http://jsfiddle.net/uVt7X/
精彩评论