← Back to index

How would you select an element in HTML using JS?

Created: 2015-12-10 06:38  |  Updated: 2015-12-10 06:40  |  Source: desktop.mac
Pure Javascript
Based in your use of .find, you basically want to know whether a node is contained in another node. Every DOM node has a method .contains, so all you have to do is iterate over the collection of DOM elements and call that method:
var contained = false;
for (var i = 0; i < searchControls.length; i++) {
   
if (searchControls[i].contains(e.target)) {
        contained 
= true;
       
break;
   
}
}

jQuery Approach