<div id = "n1" onclick = "oknoblock (this)">

function oknoblock(el) { alert(el); el.firstElementChild.style.display='block'; 

In IE 8, it says that firstElementChild is null or not an object, everything works fine in other browsers.

alert in IE 8 simply gives [object] ... other browsers [object HTMLDivElement]

How to transfer this so that its IE 8 sucks?

  • Just copy the function oknoblock (el) {var node = window.event? Event.srcElement code: el; firstElementChild = null; for (; node; node = node.nextSibling) {if (node.nodeType === 1) {firstElementChild = node; break; }} alert (node); firstElementChild.style.display = 'block'; } and do not change anything! Tested working! - Rules
  • And in which browsers did the error occur? - Rules

1 answer 1

In browsers, IE <9, there is a window.event.srcElement property, similar to this .

Quote from learn.javascript.ru

UPD :

 <div id="n1" onclick="oknoblock(this)"> function oknoblock(el){ var node = window.event?event.srcElement:el; firstElementChild = null; for ( ; node; node = node.nextSibling) { if (node.nodeType === 1) { firstElementChild = node; break; } } alert(node); firstElementChild.style.display='block'; } 

UPD 2 As I have already said on HashCode :

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

  • Here ... added - Rules
  • Everything corrected atoms with C ++ while you switch to Js .. everything needs to be remembered - Rules
  • So you were told by me to see my UPD 2 to the answer - Rules
  • What will the function look like? I'm already all ... stuck together - Nuboyd
  • Here's the final code in upd look - Rules