473,566 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Element in a td accessing parent <tr> element

I have an HTMLInputElemen t in a <td>. I want to access all the <td>'s
in the same row as the input element.

var tr=theInputElem ent.parentNode. parentNode;

Why isn't the input element's parent's parent the <tr> node in
Firefox? Internet Explorer seems to think so. How can I get the <tr>
node (so I can iterate through its children) in Firefox?

Why does this stuff have to be such a humongous god-forsaken
nightmare?? (sorry, working-late-bitterness)

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #1
3 11637
Christopher Benson-Manica wrote:
var tr=theInputElem ent.parentNode. parentNode;


You can always use a general-purpose function like this:

function getParentByTagN ame(obj, tagName) {
tagName = tagName.toLower Case();
while (obj!= null && obj.tagName!=nu ll && obj.tagName.toL owerCase() !=
tagName) {
obj=obj.parentN ode;
}
return obj;
}

then do:

var tr = getParentByTagN ame(theInputEle ment,"tr");

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #2
Christopher Benson-Manica wrote:
I have an HTMLInputElemen t in a <td>. I want to access
all the <td>'s in the same row as the input element.

var tr=theInputElem ent.parentNode. parentNode;

Why isn't the input element's parent's parent the <tr>
node in Firefox? Internet Explorer seems to think so.
In the DOM generated from valid HTML in Mozilla/Firefox the parent of
the parent of the child of a TD will be a TR. If that is not the case
then my guess (and it will have to be a guess because you have not
posted the mark-up with which the script is interacting) is that the
FORM element has been placed in an invalid location in the TABBLE and
you are experiencing differences in the DOM resulting from differences
in HTML error correction strategies. As no standards could be applied to
error-correction strategies, and the approach taken by any individual
browser (at least the commercial ones) are not published so cannot be
reproduced in other browsers, there is no reason to expect any two
browsers to generate structurally similar DOMs from invalid HTML.
How can I get the <tr> node (so I can
iterate through its children) in Firefox?
If the HTML is valid then Matt's approach will work, as should your
original. But if the HTML is not valid then Mozilla/Firefox's DOM will
be determined by the actual HTML used and no answer can be suggested
without seeing the mark-up.
Why does this stuff have to be such a humongous god-forsaken
nightmare?? (sorry, working-late-bitterness)


Problems in scripting that follow from invalid HTML are usually the
result of assuming that because various browsers happily display the
page in a more or less consistent way they will also produce
structurally similar DOMs from that mark-up. If the result is a
nightmare it is a nightmare of the authors own creation, and there is no
shortage of advice to use valid HTML when attempting to make cross
browser web pages (though it is often not made clear that it is in the
scripting of those web pages that value of valid mark-up is most
aparent).

Richard.
Jul 23 '05 #3
Richard Cornford <Ri*****@litote s.demon.co.uk> spoke thus:
If the HTML is valid then Matt's approach will work, as should your
original. But if the HTML is not valid then Mozilla/Firefox's DOM will
be determined by the actual HTML used and no answer can be suggested
without seeing the mark-up.


The actual markup was a little too complicated to post. In any case
the markup passed the W3C validator, so I'm not sure what could have
been wrong with it. I appreciate your judicious response to my
frustration.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #4

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

Similar topics

2
3654
by: John Geddes | last post by:
In both IE6 and Netscape 7: insertRow method of tbody is behaving as expected: - inserts a new row - increases tbody.rows.length BUT deleteRow is not doing the opposite. It DOES delete the row, but it adds a <TR></TR> pair just before the </TBODY> and that leaves the tbody.rows.length count unchanged.
7
2105
by: F. Da Costa | last post by:
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>
4
7229
by: El Diablo | last post by:
Hi there, I'm trying dynamically generate extra rows in a table. So far this achieves this task within the tHead segment: theTable.tHead.appendChild(document.createElement('TR')) ....but this only gives me table rows with no table data cells. So I would like to know if it's possible to create several <TH> within the tHead row using...
4
5822
by: Dominic | last post by:
I'm looking for a HTML editor that can match the opening and closing HTML tags such as <TR> </TR>, <TD> </TD> I think Dreamweaver does that, right? Even if it does, it may be too expensive for my purpose. Can you suggest any free or inexpensive HTML that can do that? Thanks Dominic
3
3688
by: Dunc | last post by:
I have a data list control with 3 columns. I want every second *row* to have a dfferent CSS class. Can someone tell me how to access the parent tablerow, and add a cssclass? I'm guessing I'll need to put some code in the itemcreated or itemdatabound? Thanks in advance, Duncan ---/ snip /---
1
2211
by: prefersgolfing | last post by:
I'm not using Master Pages, yet I'd like to display the contents of an HTML page within a <table><tr><td> on a .aspx. I have a lengthy guide already paginated in html. I'd like to embed the pages "as is" in the new 2.0 app without using Master Pages or creating new ..aspx's. I'm looking for the quickest way to the finish line. Any...
5
2930
by: mahesr | last post by:
I want to match some particular text between <tr>and </tr> or <td>and </td>.... in PHP. like below............ <table><tr> CATEGORY: <td><font face="Verdana" size="1" color="#A000A0"> Wedding Accessories
3
1713
by: jack | last post by:
Hi all im Creating a report in HTML with the help of dotnet.. im creating a which shows a data of 12 months .. the forst row of the column contains month names.. and the following data.. The table which contains a data is under div which has a scroll bar.. What in trying to do is freeze the first row of the table which is been generated.....
7
2776
by: Xiaoyan | last post by:
Hi,everyone: I have a problem now. I can't get the information between the <tr><td> and </td></tr>. for example: I use this regular expression can't get it, I don't know why. $test=~/<tr><td>(.*)<\/td><\/td>(.*)<\/td><\/tr>/ms; <tr><td>station</td> <td>station number/identification, see chart above: <br> B = GoMoos buoy B location<br> S...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.