javascript - Using Wildcards to Search Arrays in JS -



javascript - Using Wildcards to Search Arrays in JS -

i'm wondering if possible create array of elements , create event listener using wildcard trigger when of these elements interacted with. sample of might like:

var e = new array(); e[1] = document.getelementbyid('some-element'); e[2] = document.getelementbyid('some-other-element'); e.onmouseup = function() { if(e == e[1]) { //some code here } else if (e == e[2]) { //some code here } }

not wildcard allow bind 1 event handler elements - event delegation:

document.body.addeventlistener('mouseup', function (event) { var target = event.target; if (target == e[1]) { //some code here alert('some-element'); } else if (target == e[2]) { //some code here alert('some-other-element'); } }, false);

this works due fact event bubbles dom tree until reaches body it's detected, , there necessary action dispatched.

here demo approach: http://jsfiddle.net/jwoxnn3d/

javascript arrays wildcard elements

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -