473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

[IE vs Gecko & DOM] Getting text from a <div> in a <tr>

Hi,

I' looking to retrieve ProdName1 form the <tr> below.

<tr id="1-1-1" class="even">
<td>
<div class="tier4">
<a href="#" class="leaf"></a>
ProdName1
</div>
</td>
<td><input type="checkbox" name="checkbox$2" checked="1" onClick="setCheckbox(this);"/></td>
<td><input type="text" name="text2Edit$2" value="100" align="right"/></td>
</tr>

In Gecko it works as follows.
var vals = r.getElementsByTagName("div");
obj = vals[0];
_searchValues[_searchValues.length]=obj.textContent;

obj.textContent retrieves ProdName1 without any problem in *Gecko*

Obviously I also need to do this with IE and obviously the above does *not* work.
Does anybody has a suggestion as to how this can be accomplished using IE?

TIA,
Fermin DCG
Jul 20 '05 #1
7 2085
On Fri, 12 Dec 2003 10:04:57 +0100, F. Da Costa <da*****@xs4all.nl> wrote:
Hi,

I' looking to retrieve ProdName1 form the <tr> below.

<tr id="1-1-1" class="even">
<td>
<div class="tier4">
<a href="#" class="leaf"></a>
ProdName1
</div>
</td>
<td><input type="checkbox" name="checkbox$2" checked="1" onClick="setCheckbox(this);"/></td>
<td><input type="text" name="text2Edit$2" value="100" align="right"/></td>
</tr>

In Gecko it works as follows.
var vals = r.getElementsByTagName("div");
obj = vals[0];
_searchValues[_searchValues.length]=obj.textContent;

obj.textContent retrieves ProdName1 without any problem in *Gecko*


Well you could get the tr element using getElementById and then walking
down the tree IF you can guarantee that structure. Myself I might well
put an id on the <div> and doing a getElementById on that.

--
Andy Leighton => an***@azaal.plus.com
"The Lord is my shepherd, but we still lost the sheep dog trials"
- Robert Rankin, _They Came And Ate Us_
Jul 20 '05 #2
Andy Leighton wrote:
On Fri, 12 Dec 2003 10:04:57 +0100, F. Da Costa <da*****@xs4all.nl> wrote:
Hi,

I' looking to retrieve ProdName1 form the <tr> below.

<tr id="1-1-1" class="even">
<td>
<div class="tier4">
<a href="#" class="leaf"></a>
ProdName1
</div>
</td>
<td><input type="checkbox" name="checkbox$2" checked="1" onClick="setCheckbox(this);"/></td>
<td><input type="text" name="text2Edit$2" value="100" align="right"/></td>
</tr>

In Gecko it works as follows.
var vals = r.getElementsByTagName("div");
obj = vals[0];
_searchValues[_searchValues.length]=obj.textContent;

obj.textContent retrieves ProdName1 without any problem in *Gecko*

Well you could get the tr element using getElementById and then walking
down the tree IF you can guarantee that structure. Myself I might well
put an id on the <div> and doing a getElementById on that.

obj already contains the <div> so that is not the problem.
The trick lies in getting hold of the text *without* the <a> coming along (like in using childNodes[0])
Even IE 6 gives me an undefined whilst trying to get to 'textContent'
Jul 20 '05 #3
F. Da Costa wrote:
Hi,

I' looking to retrieve ProdName1 form the <tr> below.

<tr id="1-1-1" class="even">
<td>
<div class="tier4">
<a href="#" class="leaf"></a>
ProdName1
</div>
</td>
<td><input type="checkbox" name="checkbox$2" checked="1"
onClick="setCheckbox(this);"/></td>
<td><input type="text" name="text2Edit$2" value="100"
align="right"/></td>
</tr>
Changed the HTML to
<tr id="1-1-2" class="odd"> <td>
<div class="tier4"> <a href="#" class="leaf">ProdName136</a>
TProdName136
</div> </td>
<td><input type="checkbox" name="checkbox$3" onClick="setCheckbox(this);"/></td>
<td><input type="text" name="text2Edit$3" value="" align="right"/></td>
</tr>
In Gecko it works as follows.
var vals = r.getElementsByTagName("div");
obj = vals[0];
_searchValues[_searchValues.length]=obj.textContent;
Changed the js to
vals = r.getElementsByTagName("div");
// Since there could be an <a> and a normal text in the <div> get them both
// The last childNode contains the 'normal' text
div = vals[0];
_searchValues[_searchValues.length]=div.childNodes[div.childNodes.length-1].nodeValue;
obj = r.getElementsByTagName("a")[0];
_searchValues[_searchValues.length]=obj.nodeValue;
obj.textContent retrieves ProdName1 without any problem in *Gecko*

Obviously I also need to do this with IE and obviously the above does
*not* work.
Does anybody has a suggestion as to how this can be accomplished using IE?

TIA,
Fermin DCG

Jul 20 '05 #4
"F. Da Costa" <da*****@xs4all.nl> writes:
obj already contains the <div> so that is not the problem.
The trick lies in getting hold of the text *without* the <a> coming along (like in using childNodes[0])
Addressing child nodes by fixed offset numbers should be
avoided. Elements won't have the same offset in different browsers (IE
doesn't include all-whitespace text nodes in the DOM tree, Mozilla does).
Even IE 6 gives me an undefined whilst trying to get to 'textContent'


The property "textContent" is part of the comming W3C DOM 3
specification, which very few browsers support (IE still struggles
with, e.g., DOM 2 Events). It might be equivalent to the IE property
"innerText", but that won't help you in other browsers. This should work
in any W3C DOM compliant browser:

function getTextContent(node) {
if (node.nodeType == 3) {return node.nodeValue;} // text node
if (node.nodeType == 1) { // element node
var text = [];
for (var chld = node.firstChild;chld;chld=chld.nextSibling) {
text.push(getTextContent(chld));
}
return text.join("");
}
return ""; // some other node, won't contain text nodes.
}

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Lasse Reichstein Nielsen wrote:
"F. Da Costa" <da*****@xs4all.nl> writes:

obj already contains the <div> so that is not the problem.
The trick lies in getting hold of the text *without* the <a> coming along (like in using childNodes[0])

Addressing child nodes by fixed offset numbers should be
avoided. Elements won't have the same offset in different browsers (IE
doesn't include all-whitespace text nodes in the DOM tree, Mozilla does).

Even IE 6 gives me an undefined whilst trying to get to 'textContent'

The property "textContent" is part of the comming W3C DOM 3
specification, which very few browsers support (IE still struggles
with, e.g., DOM 2 Events). It might be equivalent to the IE property
"innerText", but that won't help you in other browsers. This should work
in any W3C DOM compliant browser:

Thx for the snip, much appreciated.

Had run into the nodeType as well but wasn't to sure what to do whith them.
Would it be save to assume that their definitions are described somewhere on the w3c?
What, in your your opinion, is the most reliable source for obtaining the things like the nodeType definitions,
functions pertaining to standard objects/ the DOM model etc?
function getTextContent(node) {
if (node.nodeType == 3) {return node.nodeValue;} // text node
if (node.nodeType == 1) { // element node
var text = [];
for (var chld = node.firstChild;chld;chld=chld.nextSibling) {
text.push(getTextContent(chld));
}
return text.join("");
}
return ""; // some other node, won't contain text nodes.
}

/L

TIA
Fermin DCG
Jul 20 '05 #6
"F. Da Costa" <da*****@xs4all.nl> writes:
Had run into the nodeType as well but wasn't to sure what to do
whith them. Would it be save to assume that their definitions are
described somewhere on the w3c?
Yep: <URL:http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247>
What, in your your opinion, is the most reliable source for obtaining
the things like the nodeType definitions, functions pertaining to
standard objects/ the DOM model etc?


The W3C DOM specifications are available on their web page. I have links
to them here:
<URL:http://www.infimum.dk/HTML/references.html#ref_1_5>

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
Lasse Reichstein Nielsen wrote:
"F. Da Costa" <da*****@xs4all.nl> writes:

Had run into the nodeType as well but wasn't to sure what to do
whith them. Would it be save to assume that their definitions are
described somewhere on the w3c?

Yep: <URL:http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247>
What, in your your opinion, is the most reliable source for obtaining
the things like the nodeType definitions, functions pertaining to
standard objects/ the DOM model etc?

The W3C DOM specifications are available on their web page. I have links
to them here:
<URL:http://www.infimum.dk/HTML/references.html#ref_1_5>

Thx, exactly what i was looking for.
Much appreciated.

/L

DCG
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Thompson | last post by:
When I put a <div ...> inside a <table> specification, functionality is not there. When I put the <table> inside the <div> everything works. Why is that?
8
by: F. Da Costa | last post by:
Following is a snippet of html in which I hide a whole table and try to hide a single row. Here is my question (plz don't chew my head off if its css related instead): Why does the divTable...
55
by: Ton den Hartog | last post by:
Stupid basic question but I find it horribly imposible to find the answer elsewhere... :-( I want to have a piece of text in my HTML page and want to be able to change it in a Javascript...
7
by: Herbman | last post by:
Hi, I'm trying to position a <tr> ("row") element with CSS. The table itself is positioned with <div> tags. The problem is when I use <div> tags to position the rows within the table nothing...
19
by: CMAR | last post by:
I have the following markup. The problem is that the browser, e.g., IE6, inserts several lines of blank space between the <div> and the following table. Is there a way to minimize that vertical...
44
by: Jim M | last post by:
I have had great success with using <iframe> with overflow-y set to auto. I can get a similar look with the <iframe> tag. BUT... In all cases I need to have fixed heights. Is there a way to...
4
by: David | last post by:
I attempted the following <div id="div" runat="server"> <tr><td></td></tr> <tr><td></td></tr> </div> This is to hide a group of rows depending on some business rules in my code behind.
3
by: John Pote | last post by:
1. Horizontal centering a <divin browser window. The current trend seems to be to place page content in a fixed width area in the middle of the browser window. How is this achieved? If I use a...
7
by: cmrhema | last post by:
Hi, I have two questions. 1. I have heard that replacing a <tr> <td> with <div> tags increases the rendering speed. Is it so, and if yes which speed does it increase, rendering speed or loading...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.