posted 20 years ago
Hi
I am having some issues while trying to get the parent of an <a> element in javascript. The <td> element of my table contains an 'IMG' tag followed by 'A'(href) tag. On clicking the A element tag text, i execute a javascript passing 'this' as its parameter and in the script, I try to access the parent of the A element tag by using this.parentNode. It should return me the TD elemet tag. However ,it returns an undefined object eventhough upon displaying the childnodes of the TD element tag, the 'A' element is listed as one of its children.
Does anyone have an idea why it doesnt return the parent?
Please help.
Here is the sample code.
<html>
<head>
...inline style sheet
<script>
function changeclass(current)
{
current.parentNode.className=yyy;
}
</script>
</head>
<body>
<table>
<tr>
<td class=xxx>
<img src='test.gif'>
<a href="javascript:changeclass(this)test.html'>click here</a>
</td>
</tr>
</table>
</body>
Thanks