I need to be able to have the next element / previous element to change the background color with the current element. How do I do that. The element that I am working is TR, table row, and nextSibling, previousSibling doesn’t do the trick for me, don’t know why ?
Share
I think we have a case here of even the “good” browsers behaving in an extremely annoying way.
Take for example my following table, where the HTML looks like the following:
When I open this up in Firefox and go to the console and run the following snippets, notice the how nextSibling behaves:
I’ve read about this somewhere, and I forget exactly where (Quirksblog, or perhaps from a talk PPK did), so then I tried the following:
This is one of those moments where our wonderful standards compliant browsers do it (IMHO) absolutely wrong.
To test, I decide to single line the HTML of my table, hence (hopefully it shows up all on one line):
And run my test again:
Benice, your idea was correct, but you got bit by what I like to think of as an implementation oversight on the browser’s part. I recommend being very careful with HTML DOM relationships cross-browser. Most of them work as expected, but sometimes they don’t.
Ahh, found an article about this after all: https://developer.mozilla.org/en/Whitespace_in_the_DOM