javascript - Element getElementsByClassName IE -
this question has answer here:
i have code document.getelementsbyclassname
ie
if (!document.getelementsbyclassname) { // 4ie document.getelementsbyclassname = function(classname) { var elarray = [], tmp = document.getelementsbytagname("*"); regex = new regexp("(^|\\s)" + classname + "(\\s|$)"); ( var = 0; < tmp.length; i++ ) { if ( regex.test(tmp[i].classname) ) { elarray.push(tmp[i]); } } return elarray; }; }
how change code make work single html element? div.getelementsbyclassname('123')
you have couple options. first since getelementsbyclassname returns array, if know based on class name passed it's going grab 1 element can getelementsbyclassname('123')[0] 1 element. if grabs multiple elements getelementsbyclassname('123')[0] return first one.
second add id has unique singular element , use getelementbyid() function grab it.
Comments
Post a Comment