Re: Searching for text in nested table cell
- From: "JWilliams" <ZZjohnZZwilliams_esq@xxxxxxxxxxxxx>
- Date: Thu, 4 Jan 2007 00:36:35 -0000
Thanks for your help, Igor.
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:ulOTEbTLHHA.448@xxxxxxxxxxxxxxxxxxxxxxx
"JWilliams" <ZZjohnZZwilliams_esq@xxxxxxxxxxxxx> wrote in message
news:...
"Igor Tandetnik" <itandetnik@xxxxxxxx> wrote in message
news:%233MQZ$dKHHA.4912@xxxxxxxxxxxxxxxxxxxxxxx
JWilliams <ZZjohnZZwilliams_esq@xxxxxxxxxxxxx> wrote:
In the searchTable subroutine above the required text is matched
using:
If InStr(TD.innerText, "target cell") Then
However, because the target cell is nested, simply looking at
TD.innerText is insufficient because it can contain the text of
cells lower down the DOM hierarchy, resulting in a spurious match
as shown by the debug line beginning 4 below:
You can check TD.all.length to look for a cell that doesn't have any
child elements.
That works nicely for the simplified example I posted, however the
real target cell has the search text within a <span> </span> tag,
which means that the cell has 1 child element. Looking for a cell
which has 1 child element and contains the text results in a couple
of spurious matches.
You can use TD.all.tags("td").length to check that the cell has no nested
<td> elements.
It's a pity you can't tell TD.innerText to only return text in the
immediate cell and not any nested cells.
You can use the DOM for that. Something along these lines:
const NODE_TEXT = 3;
var elem; // the element to get text content from
var children = elem.childNodes;
var text = "";
for (var i = 0; i < children.length; ++i) {
var child = children[i];
if (child.nodeType == NODE_TEXT) {
text += child.nodeValue;
}
}
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- References:
- Re: Searching for text in nested table cell
- From: JWilliams
- Re: Searching for text in nested table cell
- From: Igor Tandetnik
- Re: Searching for text in nested table cell
- Prev by Date: Re: Cannot enumerate frameset documents under IE7
- Next by Date: Form submit not loading web page
- Previous by thread: Re: Searching for text in nested table cell
- Next by thread: Cannot enumerate frameset documents under IE7
- Index(es):
Relevant Pages
|
Loading