I have an element grabbed from document.getElementById('the_id')
. How can I get its next sibling and hide it? I tried this but it didn't work:
elem.nextSibling.style.display = 'none';
Firebug error was elem.nextSibling.style is undefined
.
I have an element grabbed from document.getElementById('the_id')
. How can I get its next sibling and hide it? I tried this but it didn't work:
elem.nextSibling.style.display = 'none';
Firebug error was elem.nextSibling.style is undefined
.
Try looping through the children of this element using something like:
Please make appropriate corrections to the syntax.
Take a look at the Element Traversal API, that API moves between Element nodes only. This Allows the following:
And thus avoids the problem inherent in nextSibling of potentially getting non-Element nodes (e.g. TextNode holding whitespace)
it's because Firefox considers the whitespace between element nodes to be text nodes (whereas IE does not) and therefore using
.nextSibling
on an element gets that text node in Firefox.It's useful to have a function to use to get the next element node. Something like this
then you can do
because nextSibling can be a text-node or other node type