Skip to content

Instantly share code, notes, and snippets.

@bbg
Created November 11, 2015 17:42
Show Gist options
  • Save bbg/fda9f405ea32d1c2bcb3 to your computer and use it in GitHub Desktop.
Save bbg/fda9f405ea32d1c2bcb3 to your computer and use it in GitHub Desktop.
Event Listener Native Javascript width jQuery Style
<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