getElementsByTagName

All we know that getElementsByTagName() a DOM function in Javascript is used to get all the child elements for an particular element.Consider this following scenario I have an table with the id as “parentTable”, which has many child tables in it. so my structure will be like this,
			<table id='parentTable'>
				<tr>
					<td>
						<table id='childTable1'>
							<tr>
								<td>My First Article</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		
If i’m going to use parentTable.getElementByTagName(”tr”), i’ll be getting the count as 2, Which is what i’m not looking for. I wanted to get the count as 1.Guys please give some alternative suggesstion.
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Tags: ,

No Responses to getElementsByTagName

  1. Java Blog says:

    You may want to use document.getElementById() to get a single element with given id. The method document.getElementByName() by default returns all the matching elements from the DOM. More on getElementByName: http://www.w3schools.com/htmldom/met_doc_getelementsbyname.asp

Leave a Reply

Name and Email Address are required fields. Your email will not be published or shared with third parties.

Get Adobe Flash player