Michel wrote:
[...]
Hi Lee, sorry for my top-posting.
Anyway, I need the link as I want 2 seperate alerts. One for when I click
the background and one for the message itself.
Is that possible?
Yes. There are a couple of ways to do it, below is one. You can use an
onclick on the TD and then use the event properties to see what was
clicked on, or you can put an onclick on each element and go from there.
If you want to stop navigation for some reason, then you need an onclick
on the A element that returns false (or true for navigation to occur).
I've returned false so that the link isn't followed, the value returned
(either true or false) can be based on some condition.
To stop both events firing when the link is clicked, use stopPropagation
(W3C event model) and cancelBubble (IE event model).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Click play</title>
<script type="text/javascript">
function color(e, value)
{
var e = e || window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
alert(value);
return false;
}
</script>
</head>
<body>
<table>
<tr>
<td onclick="color(event, 'headerbackground');"
style="width: 10em; border:1px solid blue;">
<a href="http://www.w3.org/"
onclick="return color(event, 'header');">W3.org</a>
</td>
</tr>
</table>
</body>
</html>
--
Rob