javascript - Element getElementsByClassName IE -


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

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -