»
EnglishFrenchVietnamese

Print - Prototype Dollar Function - JavaScriptBank.com

Full version: jsB@nk » Snippet » Prototype Dollar Function
URL: http://www.javascriptbank.com/prototype-dollar-function.html

Prototype Dollar Function © JavaScriptBank.comThe dollar function is a simple way to grab an element quickly. It not only takes in strings, it takes objects too. Instead of: document.getElementById('a'); use: $('a'). If you want a whole collection of elements, you can simply do this: $('a','b',obj,obj2,'c','d');.

Full version: jsB@nk » Snippet » Prototype Dollar Function
URL: http://www.javascriptbank.com/prototype-dollar-function.html



JavaScript
<script type="text/javascript">// Created by: Dustin Diaz :: http://www.dustindiaz.com/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<elements.length;i++ ) {    alert(elements[i].id);  }}// ........................................................</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->