Im trying to make a popup div (when a text-box value changes) and it can be closed (visibility: none) by clicking anywhere outside the div. Similar to Google suggestion drop-dow
Here's an example with jQuery. If you click on the "test" text, you make the other text appear. Clicking anywhere else except than on the newly appeared text makes it disappear.
This works because if the click happened inside (the .toggle
object, in this case), we call e.stopPropagation()
for the click event to stop propagating further up towards the entire window.
However if the click occurred somewhere else, it propagates directly to the window and makes .toggle
disappear.
See example of it working on jsfiddle.
test
asdasdsa