Code
gEle = function(a){ return ( (typeof a==="string") ? document.getElementById(a) : a ); };
Parameters
- a (string of text or object)
- The string with the id of the object or one DOM object, this second option is for the use with jQuery
Returned value
The DOM object with the given id or null if not exist
Samples
Using a jQuery object
Change the color of the first paragraph of the webpage to redp1=jQuery("p")[0]; gEle(p1).style.color="red";
Change style to object with id=”div1″
<div id="div1"> Change color to red </div> <a href="gEle('div1').style.color='red';">Press to change color</a>