javascript - Using Wildcards to Search Arrays in JS -


I am thinking that it is possible to create an array of elements and then create an event listener using a wildcard that Will trigger when interacting with any of these elements. A sample of how this may look like:

  var e = new array (); E [1] = document.getElementById ('some elements'); E [2] = document.getElementById ('some other elements'); E.onmouseup = function {if (e == e [1]) {// some code here} and if (e == e [2]) {// some code here}}    

Actually there is no wildcard , but something that only allows you to have an event handler All elements will allow binding - Event delegation:

  document.body.addEventListener ('mouseup', function (event) {var target = event.target; if (target == E [ 1]) Some code warnings here ('some element');} and if (target == E [2]) {// some code warnings here ('some un Other elements');}}, false); Due to this fact it works because the DOM transports the tree to the bubble until the code reaches  , and requires it from there. The action is transmitted.  

There is a demo with this approach:

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -