function oknoblock(el) { var els = window.document.getElementsByClassName('okno'); for (var i=0; i<els.length; ++i) {els[i].style.display='none';}; el.firstElementChild.style.display='block'; }; 

IE 8 writes: The object does not support this property or method. Line 2 character 1.

In HTML, the function is called like this: <div id = "n1" onclick = "oknoblock (this)">

    2 answers 2

     // "getElementsByClassName" не определен IE, // так что этот метод можно реализовать в JavaScript 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; } }; 

    Taken from: http://web.izjum.com/getelementsbyclassname-on-javascript

    • The second line has passed, thank you very much ... now firstElementChild.style is null or is not an object in the same IE 8 ... it is invincible - Nuboyd
    • It's simple. IE does not have such a property. (el.firstElementChild || el.children [0] || el.firstChild || {}). style.display = 'none'; It seems that such a record should work everywhere. Although the last {} meaningless to put in this case ... - Dobby007
    • But hildren [0] can return not only a tag but also a text node and firstChild as well! And @ustal wants to receive TEG! - Rules

    Instead of firstElementChild in IE <9, use:

     var node = this.firstChild, firstElementChild = null; for ( ; node; node = node.nextSibling) { if (node.nodeType === 1) { firstElementChild = node; break; } } 

    in firstElementChild will be the first tag

    Taken from stack overflow site