Created
November 11, 2015 17:42
-
-
Save bbg/fda9f405ea32d1c2bcb3 to your computer and use it in GitHub Desktop.
Event Listener Native Javascript width jQuery Style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
// self executing function here | |
(function() { | |
$ = function(selector) { | |
var selectorType = 'querySelectorAll'; | |
if (selector.indexOf('#') === 0) { | |
selectorType = 'getElementById'; | |
selector = selector.substr(1, selector.length); | |
} | |
var element = document[selectorType](selector); | |
if (selectorType === 'querySelectorAll') { | |
Object.defineProperties(element, { | |
click: { | |
enumerate: false, | |
set: function(f) { | |
for (var i = 0; i < this.length; ++i) { | |
this[i].onclick = f; | |
} | |
} | |
} | |
}); | |
} | |
return element; | |
}; | |
})(); | |
$('input').click = function() { | |
alert('Demo'); | |
} | |
</script> | |
<button class="selectt">Is it working huh?</button> | |
<button class="selectt">Second Button too ?</button> | |
<input class="selectt" type="button" value="Third Button Index Must be equal to 2(Two) ?? == " /> | |
<input id="InputById" type="button" value="Single Element ById = '#InputById' " /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment