gEle=function(a){ return ((typeof a==="string")?document.getElementById(a):a); };
Parameters
This function only needs the string of the id of the object and returns the dom element with that id.Sample usage
In our html source code we insert a DIV element with id “gEleSamp”<div id="gEleSamp" style="border:solid 1px #ccc;">sample div</div>The result of our code:
sample div
We access to the object with gEle using their id and we change the font color to red:
<span onclick="gEle('gEleSamp').style.color='#f00'">Test </span>Test the code pressing the following link:Test