"2obvious" <Ev************@gmail.com> writes:
var objNode = getElementById("content").getElementsByTagName("h1 ")[0];
I assume that objNode is not null (i.e., the page contains what you
expect).
objNode.style.display = "none";
Try adding
alert(objNode.nextSibling.nodeType);
(explanation later)
objNode.nextSibling.style.display = "none";
Unfortunately, this (and several other slight variations on this) was
unable to recognize "nextSibling" as a function.
Good, because "nextSibling" is not a function, but a property (as you
are using it).
What is it I'm not understanding here?
(On a related note, I probably would have used the .firstChild()
function to grab that header, but I had no luck with that either, and
.nextSibling is the more serious problem.)
I will wager a guess: You are using a Gecko based browser (e.g.,
Mozilla or Firefox).
If you add the alert from above, it will tell you what kind of DOM
node the nextSibling node is. To be an element node (and have a style
property), the value of nodeType must be 3. I'm guessing that it will
alert "7", the type of a text node. It is the text node that contains
the whitespace (probably a newline and some spaces) between the "h1"
element and the following element.
You can't just use .nextSibling.nextSibling to step over the text node,
because IE, in it's infinite wisdom, does not include text nodes that
only contain whitespace in its document model. You need to find the
next element. You can use a function like this;
---
function nextSiblingElement(elem) {
do {
elem = elem.nextSibling;
} while (elem && elem.nodeType != 3);
return elem;
}
---
Good luck.
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'