Javascript not displaying in internet explorer 7 and 8

<>

This question already has an answer here:

Answers


Try to use: var collapsables = document.querySelector('.collapsable');

querySelector supported from IE8

But if you need IE7, try to use dirty hack:

if(document.getElementsByClassName == undefined) { 
   document.getElementsByClassName = function(cl) { 
      var retnode = []; 
      var myclass = new RegExp('\\b'+cl+'\\b'); 
      var elem = this.getElementsByTagName('*'); 
      for (var i = 0; i < elem.length; i++) { 
         var classes = elem[i].className; 
         if (myclass.test(classes)) { 
            retnode.push(elem[i]); 
         } 
      } 
      return retnode; 
   } 
}; 

You should understand - this is very slow operation. This function iterates all DOM elements


I'll bet this will get closed because it is a duplicate pretty soon, but Web_Designer has a nice working solution posted here.

Web_Designers solution for IE versions prior to IE9:

function getElementsByClassName(node, classname) {
    var a = [];
    var re = new RegExp('(^| )'+classname+'( |$)');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}

Usage:

var tabs = getElementsByClassName(document.body,'collapsable');

Need Your Help

simple java hierarchical issue

java data-structures hierarchy

I am having a problem to deal with following data.