...

View Full Version : Element object from a Node object



leep
04-30-2008, 03:19 PM
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.

liorean
04-30-2008, 08:18 PM
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.

Kor
05-01-2008, 08:23 AM
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:


var cellsCollectionInATableRow=TableRowDOMobject.getElementsByTagName('td');



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum