Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the name of a <td> element

Status
Not open for further replies.

nminaker

Technical User
Jun 17, 2004
19
I have an onload event in the body that runs the following function:

Code:
function prepShowMsgs()	{
  var bqs = document.getElementsByTagName("blockquote");
  for(i = 0; i < bqs.length; i++) {
    var tds = document.getElementsByName(bqs[i].id);
    for(j = 0; j < tds.length; j++) {
        tds[j].onclick = function() {
          document.getElementById(this.name).style.display = 'visible';
        }
    }
  }
}

The <td> tags' names are the same as the ID of the element that they should show. But when I just put in "this.name" in an alert box it shows "undefined"... Whats the problem?

Thanks!
 
About the problem you posted for, I don't see enough code to help, but I do see that this statement:

Code:
document.getElementById(this.name).style.display = 'visible'

is incorrect. Valid display values are "block", "none", "inline"


[monkey][snake] <.
 
Something like this?
Code:
<td id="fred" name="fred">

That way you can getElementById or getElementByName
 
Valid display values are "block", "none", "inline"

It actually goes a lot farther than that, although you are correct that "visible" is not a valid value.


-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
uncle_rico_thumb.jpg
 
Yeah, I realize I made a mistake putting 'visible'... it really should be "block"...

I'd prefer not to have to change the <td> elements so they have an ID and name... as it stands now there are three <td> elements with the same name and I want them all to have the same onclick function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top