Andrew Andrew - 1 year ago 185
Javascript Question

Javascript `nextElementSibling` from comment undefined in IE


When using IE, if I have a comment and try to access the

property from it, I get
. However, if I try to access
from something not a comment, I get my expected value. This behavior is only on IE, and I'm having a hard time trying to figure out why.

I've Googled around quite a bit, and unless I'm not searching for the right terms, I can't seem to find an answer. Any help would be appreciated.

<div id="test">
Next Element Sibling is undefined

<div id="test2">
Next Element Sibling is found

Answer Source

It's not just IE, it's older browsers in general. nextElementSibling was a property of Elements only, not of comment nodes. Only recently the interface was changed to make the property available on other kinds of nodes as well.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download