/ Published in: JavaScript
instead of document.getElementById('a');, you’d simply just do this instead:
$('a');.
And if you wanted a whole collection of elements, you can simply do this:
$('a','b',obj,obj2,'c','d');
$('a');.
And if you wanted a whole collection of elements, you can simply do this:
$('a','b',obj,obj2,'c','d');
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function $() { var elements = new Array(); for (var i = 0; i < arguments.length; i++) { var element = arguments[i]; if (typeof element == 'string') element = document.getElementById(element); if (arguments.length == 1) return element; elements.push(element); } return elements; } // Sample Usage: var obj1 = document.getElementById('element1'); var obj2 = document.getElementById('element2'); function alertElements() { var i; var elements = $('a','b','c',obj1,obj2,'d','e'); for ( i=0;i