[thelist] trouble with the DOM and spaces
Peter-Paul Koch
gassinaumasis at hotmail.com
Sun Aug 29 06:51:47 CDT 2004
>so it seems i've hit a little snag, in my otherwise great script i'm
>writing. i have this html code, as formated below:
>
><dl>
> <dt>some titel</dt>
> <dd>something goes here</dd>
></dl>
>
>and i'm trying to find the nextSibling to the DT. in IE6, it reports DD but
>in Firefox it says #text, refering to the hard return there. my question is
>there any way around this, coding wise? i mean i could reformat my document
>so there is no space but then it becomes quite unreadable, especially
>considering it is a very long html file. and testing to see whether i'm
>using IE6 or Firefox seems way too late 1990's. maybe i'm missing the use
>of the function and DOM? thoughts?
You've stumbled upon one of the most nasty problems in W3C DOM development.
My solution is:
var dt = [dt element];
var nextSib = dt.nextSibling;
while (nextSib.nodeType != 1)
nextSib = nextSib.nextSibling;
Now the script checks if the nextSibling is an element node (type 1). If it
isn't (ie. if it encounters an empty text node) it moves to the next
nextSibling.
-------------------------------------------------------------------
ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
http://www.quirksmode.org/
Column "Keep it Simple": http://www.digital-web.com/types/keep_it_simple/
------------------------------------------------------------------
_________________________________________________________________
Hotmail en Messenger on the move
http://www.msn.nl/communicatie/smsdiensten/hotmailsmsv2/
More information about the thelist
mailing list