Tuesday, 15 February 2011

javascript - register click on everything on body except div and all its children -


I'm trying to hide some li element when clicking any element on the page Gets them or their containers ( div.dropdown_container ) I can not get it to work though.

  $ ("body"). ("Click", "*: no (div.dropdown_container, div.dropdown_container> *)", function (e) long before `` li` / / does not want to hide it, it would span I always want to show $ ("ul.dropdown_ul> li: not (#first)"). Hide ();});   

How can I change this so that everything is listener, but there is no div.dropdown_container or any child element in it?

should do this.

e.target gets the element you clicked on.

So it checks whether a click is generated or clicked on any of its children.

  $ ("body"). ("Click", function (e) {if ($ (e.target) .is ('div.dropdown_container') || $ (e.target) .closest ('div.dropdown_container'). Length) {/ / Do something else else {// do something else}});    

No comments:

Post a Comment