Click to See Complete Forum and Search --> : supress parent onClick


michelle
09-04-2003, 09:10 AM
I have two onClicks in a table as show in the table below.

Since the "a href" is in the area of the "TD", I get two alerts.

I just want the alert('href') to be called if I click on the link and alert('td') to be called if I click anywhere else in the TD.

Any thoughts?
// Michelle

<table border=1>
<tr>
<td onclick="alert('td');">
<a href="#" onClick="alert('href')">a link</a>
<br>
<br>Not a link
</td>
</tr>
</table>

Khalid Ali
09-04-2003, 09:36 AM
you will probably need to write a function where you differentiate between the src of the clicks and show the appropriate alert message.

michelle
09-10-2003, 05:30 AM
Ok, I have created a function for handling the alerts and tried numerous ways of solving my problem, but my mind is now blank.

The thing I want is to alert the element that calles the function first.
(if I click the href, the function is being called three times, but I just want to do the alert the first time. The same goes for when I click "Not a link", only the function is just called two times)

function myAlertFunction(theElement) {
alert(theElement)
}

<table border=1>
<tr id="tr" onclick="myAlertFunction('tr');">
<td id="td" onclick="myAlertFunction('td');">
<a id="href" onclick="myAlertFunction('href');">a link</a>
<br>
<br>Not a link
</td>
</tr>
</table>


I have tried this:
var count = 1;
function myAlertFunction(theElement) {
if (count == 1) {
alert(theElement)
count++;
} else {
count = 1;
}
}
Not working

Any thoughts?
// Michelle