473,405 Members | 2,445 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.

getElementsBName and <table>'s

I relatively new to JavaScript and the DOM....

I have a <table name="xxx"> and I try to a
document.getElementsByName("xxx")

I don't seem to get the <table> returned in the NodeList returned by
getElementsByName

If I do a
nl = document.getElementsByTagName("table")

I can iterate through the resultant NodeList and find node with
nl[i].name = "xxx"

Do <table>'s just not work with getElementsByName ?

Thanks
Mike
Jul 20 '05 #1
4 6062
"Mike Berger" <mb***************@skypoint.com> wrote in message
news:vp************@corp.supernews.com...
<snip>
Do <table>'s just not work with getElementsByName ?


As TABLE elements are not allowed a NAME attribute (according to the
HTML 4 DTDs) so it is probably unrealistic to expect to be able to
retrieve them from an HTML DOM by name (with getElementsByName). You may
find some browsers that will let you, in the same way that you will find
some browsers that will make all attribute values into named properties
of an element, there will be others that don't. Starting from the basis
of valid HTML is likely to significantly increase the chances of
consistent behaviour from DOM methods.

Richard.
Jul 20 '05 #2
"Mike Berger" <mb***************@skypoint.com> writes:
I relatively new to JavaScript and the DOM....

I have a <table name="xxx"> and I try to a
document.getElementsByName("xxx")
Table tags don't have a "name" attribute, so your "HTML" is not correct
HTML.
I don't seem to get the <table> returned in the NodeList returned by
getElementsByName
Which browser are you using? It seems to be consistent behavior in
the browsers I have tested, so it's probably not important.

Are you writing HTML or XHTML? The method getElementsByName works
differently in HTML and XHTML, but the problem seems to be there
in HTML, which is the more accepting of the two.
If I do a
nl = document.getElementsByTagName("table")

I can iterate through the resultant NodeList and find node with
nl[i].name = "xxx"

Do <table>'s just not work with getElementsByName ?


I don't *think* so. The getElementsByName method finds the DOM
nodes with a name property that has the right value. Tables don't
have a DOM property called "name".

Give the table an id and use getElementById instead.

/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 #3
try using id instead of name

hope this helps

Simon Christie

"Mike Berger" <mb***************@skypoint.com> wrote in message
news:vp************@corp.supernews.com...
I relatively new to JavaScript and the DOM....

I have a <table name="xxx"> and I try to a
document.getElementsByName("xxx")

I don't seem to get the <table> returned in the NodeList returned by
getElementsByName

If I do a
nl = document.getElementsByTagName("table")

I can iterate through the resultant NodeList and find node with
nl[i].name = "xxx"

Do <table>'s just not work with getElementsByName ?

Thanks
Mike

Jul 20 '05 #4
Oh... duh........

Thanks, my bad

"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:bn*******************@news.demon.co.uk...
"Mike Berger" <mb***************@skypoint.com> wrote in message
news:vp************@corp.supernews.com...
<snip>
Do <table>'s just not work with getElementsByName ?


As TABLE elements are not allowed a NAME attribute (according to the
HTML 4 DTDs) so it is probably unrealistic to expect to be able to
retrieve them from an HTML DOM by name (with getElementsByName). You may
find some browsers that will let you, in the same way that you will find
some browsers that will make all attribute values into named properties
of an element, there will be others that don't. Starting from the basis
of valid HTML is likely to significantly increase the chances of
consistent behaviour from DOM methods.

Richard.

Jul 20 '05 #5

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

Similar topics

1
by: Philo | last post by:
How do I select all <div> tags except those which contain a <table> tag somewhere within them? Example XML: <********************** sample input ***********************> <txtSectionBody>...
8
by: bearclaws | last post by:
I am looping through a list of categories and want to display the list horizontally (instead of vertically). I want to create a single row with 4 list items in each cell of the row. I thought...
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?
61
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will...
10
by: BuddhaBuddy | last post by:
Platform is DB2/NT 7.2.9 The table was created like this: CREATE TABLE MYTEST ( MYTESTOID bigint not null primary key, FK_OTHEROID bigint not null references other, FK_ANOTHEROID bigint not...
0
by: timnels | last post by:
I've got a bizzare issue where I have an XML file to load into a data set like: <conversion> <table name="parent"> <table name="child"> </table> </table> <table name="another parent"> ....
2
by: Frank van Vugt | last post by:
Hi, Not exactly a showstopper, but I noticed this behaviour: db=# create table f1 (id int, value int); CREATE TABLE db=# insert into f1 select 1 as id, null; INSERT 25456306 1
1
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...
0
by: =?Utf-8?B?R3JlZw==?= | last post by:
I've created my table and alli is fine. I name my <tdtags to make them easier to identify when my table gets large. Anyway, I am naming as such: <td id="cellName" > Now, sometimes when make a...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...

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.