...

View Full Version : Weird previousSibling results



jbot
05-25-2004, 03:28 PM
can anyone explain this bahviour to me. when i call a function to check on the id of a previous element in the tree, IE correctly identifies it, but Mozilla get's the wrong name altogether.

the first block of code is the HTML/JSP. please note, this includes Struts tags, so ignore them since they ain't relevant:


<tr>
<td id="trial-td-1-a"><div class="disabledlabel"><bean:write name="UserLogEventForm" property="userlistlabel(e1functionalArea)"/></div></td>
<td id="trial-td-1-b"></td>
<td>
<html:select property="userlist(e1functionalArea).selected" disabled="true">
<option value="" SELECTED><fmt:message key="fault.defect.e2functionalArea"/></option>
<html:options property="userlistvalue(e1functionalArea)"/>
</html:select>
</td>
<td></td>
<td><div class="errormsg"><html:errors property="userlist(e1functionalArea).selected"/></div></td>
</tr>

this next block is the JS alert used to check the id of 2nd previous sibling of the selectbox. it should return "trial-td-1-a", but it only does so in IE. Firefox get's it wrong and goes for the first previous sibling "trial-td-1-b". this is the alert call (btw: aElms[j] is the form element calling it's parent node, etc):


alert("name = " + aElms[j].parentNode.previousSibling.previousSibling.id) ;

what's going on? :confused:

liorean
05-25-2004, 03:45 PM
This looks like one of the regular whitespace issues. The first previousSibling is probably a Text node containing the whitespace in between the Element nodes.

jbot
05-25-2004, 03:51 PM
This looks like one of the regular whitespace issues.

hmmm, thot you might say that.

however, the previousSibling is empty. there is no whitespace. the cells come out as <td></td>. (or does that still count as whitespace?)

anyway, i'm not asking for the first previousSibling, but the second one, ie the the first cell in the row. so, how come IE get's it correct and not Firefox. what's that all about? :confused:

this is really holding me up! :(

nolachrymose
05-25-2004, 04:27 PM
<td id="trial-td-1-b"></td><!-- whitespace somewhere between here and
here --><td>

Hope that helps!

Happy coding! :)

jbot
05-25-2004, 05:15 PM
ahhh, that would make some sense. you mean the whitespace between elements (not necessarily tags) counts as a node? interesting.

so, basically, i shouldn't take for granted that my code will go straight to the the next element nodetype, but could jump right to gap in the markup, ie a whitespace node. that makes sense, but also kinda sucks in some scenarios.

alas, i need to test wot the nodetype is first, and from that determine how many nodes to span across.

cheers :thumbsup:

jbot
05-25-2004, 05:20 PM
alert("name = " + aElms[j].parentNode.previousSibling.previousSibling.id) ;


might be better done as:


alert("name = " + aElms[j].parentNode.parentNode.firstChild.firstChild.id)

nolachrymose
05-25-2004, 05:57 PM
ahhh, that would make some sense. you mean the whitespace between elements (not necessarily tags) counts as a node? interesting.

You should check with the DOM Inspector to see, though.

Happy coding! :)

liorean
05-25-2004, 06:00 PM
firstChild isn't limited to Element nodes, either. So, if you have any whitespace between the parent and the first element child, it will be the firstChild.

glenngv
06-01-2004, 06:36 AM
Cleaning useless whitespace in Mozilla DOM (http://www.codingforums.com/showthread.php?t=7028)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum