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
Post a Comment