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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Element object from a Node object

    In FireFox, in HTML DOM, if I have a Node object representing a specific <tr> tag, is there any way I can get the TableRow DOM object for that same TR?

    Ok, let me back up and ask the higher-level question. In FireFox, how can I get the TableRow DOM object for the TR that the user currently has text selected in (the page is in design mode, document.DesignMode = "on", allowing the user to type in/edit the page)?

    In IE I would use sel = document.selection.createRange().parentElement; and as long as sel.tagName != "TR" (and != "BODY") I keep doing sel = sel.parentElement;. I end up with the TableRow DOM object (or the Body DOM object if the selected text wasn't in a table).

    But in FireFox I'm doing sel = window.getSelection().anchorNode; and as long as sel.tagName != "TR" (and != "BODY") I keep doing sel = sel.parentNode; I end up with the generic Node object for the TR (or the Body if the selected text wasn't in a table). But I need the TableRow DOM object which has a cells collection, not the generic Node object.

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    You seem to have misunderstood the way the DOM works. An Element IS a Node. An HTMLElement is an Element. An HTMLTableRowElement is an HTMLElement.

    A single element only has a single object representation - The HTMLTableRowElement IS the Node object for a TR element, there are no ways to get a Node object for it which is not at the same time a HTMLTableRowElement.
    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
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by leep View Post
    But I need the TableRow DOM object which has a cells collection, not the generic Node object.
    Following the liorean's note, I would add that, in this case, you must create that collection like this:
    Code:
    var cellsCollectionInATableRow=TableRowDOMobject.getElementsByTagName('td');
    Last edited by Kor; 05-01-2008 at 09:51 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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