html - Native JavaScript - detect when a div is clicked away from / unfocused -


i need know when div clicked away from, in native javascript.

to test whether or not element clicked element in question using native javascript code can this

var handleclick = function(e) {    var div = document.getelementsbytagname('div')[0];    if (e.target !== div) alert('clicked outside of div');  }  document.addeventlistener('click', handleclick, false);
/* purposes of example */    div {    background: red;    width: 100px;    height: 100px;  }
<div></div>


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -