pbd22 wrote:
> <table width="54">
The `width' attribute is presentational. Use CSS instead.
> [SNIP - LOTS OF HTML HERE]
> <a href="#" onclick="Foo();">get the width attribute's value</a>
That element should be generated by client-side scripting:
<script type="text/javascript">
document.write('<a ...>...<\/a>');
</script>
Foo() would not be a constructor or a factory, and so should be foo().
> </table>
>
> When I click on the anchor tag, it returns the number "54".
>
> How do I do this?
You don't, as you cannot click on a tag if not in your source code editor.
Provided that you mean a click on the `a' element there, you have to obtain
the ancestor element object reference through iteration:
function getNextAncestor(o, sElemType)
{
if (o)
{
var rxElemType;
if (typeof sElemType == "string")
{
rxElemType = new RegExp(sElemType.toLowerCase(), "i");
}
if (rxElemType)
{
while ((o = o.parentNode))
{
if (rxElemType.test(o.tagName))
{
return o;
}
}
}
}
return null;
}
function getAncestorTableWidth(o)
{
return (getNextAncestor(o, "table") || {width: -1}).width;
}
<table width="54">
...
<tr>
<td>...<a
href="#"
onclick="window.alert(getAncestorTableWidth(this)) ; return false"
>get the width attribute's value</a>...</td>
</tr>
...
</table>
HTH
PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
|