Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
How to get ids using GetElementsByTagName
Old 09-17-2008, 12:27 PM How to get ids using GetElementsByTagName
Junior Talker

Posts: 2
Name: Michael
Trades: 0
Hi everyone!

I need to grab the ids of table rows in a dynamically created table. So, I used the following syntax:


Code:
var test = document.getElementsByTagName("tr").id;
and then alerted "test", but it doesn't work. Each <tr> has it's own uniquely generated id, so how do I grab these values?

Thanks in advance.
memerson is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-17-2008, 01:22 PM Re: How to get ids using GetElementsByTagName
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
What you're missing here, is that when you create a variable via document.getElementsByTagName("tr"), what you're actually doing is creating an array of items. Note that Elements is plural. To get the id of each tr, you must loop through the array:
Code:
var test = document.getElementsByTagName("tr");
for(var i= 0; i<test.length; i++) {
alert(test[i].id);
}
Be sure to either place this as an onload function, or else place the script down at the bottom so it runs after all the HTML is finished loading.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to How to get ids using GetElementsByTagName
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09841 seconds with 12 queries