Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67527

How to make event.target refer to a div and all its children?

$
0
0

How can I make event.target work for not just the div given but also all it's children? The best I can come up with is to either:

1) list all children in the event.target function ie:

window.addEventListener('mouseup', function (event) {

  if(event.target != div && event.target != divChild1 && event.target != divChild2 && event.target != divChild3 && event.target != divChild4 && event.target != divChild5 ... && event.target != divChildn) {

  closeWindow();

  } });

OR

2) put all the children in a class (which seems like an awful lot of html) and then just have event.target refer to that class i.e.:

window.addEventListener('mouseup', function (event) {

      if(event.target != classWithAbout50divs) {

      closeWindow();

      } });

But surely there is a way that requires less code..?

And please, no jquery. Thanks


Viewing all articles
Browse latest Browse all 67527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>