Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Weird previousSibling results

    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:

    Code:
    <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):

    Code:
    alert("name = " + aElms[j].parentNode.previousSibling.previousSibling.id) ;
    what's going on?

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #3
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by liorean
    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?

    this is really holding me up!

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <td id="trial-td-1-b"></td><!-- whitespace somewhere between here and
    here --><td>
    Hope that helps!

    Happy coding!

  • #5
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb this might have been better in that case

    Quote Originally Posted by jbot
    Code:
    alert("name = " + aElms[j].parentNode.previousSibling.previousSibling.id) ;
    might be better done as:

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

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jbot
    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!

  • #8
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •