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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -