[thelist] RE:JavaScript onClick question

Tim Kuhn Tim.Kuhn at PREMERA.com
Mon Aug 23 10:34:35 CDT 2004


Craig, 

Why not write to functions, one for the div onclick and one for the anchor
onclick, and call them from the onclick within each element? 

Such as, simplified of course:

<html>
<head><title></title></head>
<script type="text/javascript">
<!--
function divClick()
{
	alert('div onClick');
}

function linkClick()
{
  var div = document.getElementById("wrapper");
  div.onclick = null;
	alert('anchor onClick');
}
// -->
</script>

<body>
<div onClick="divClick();" id="wrapper">
 <a href=3D"#" onClick="linkClick();">Link</a> </div> </body> </html>

I hope that helps.



-----Original Message-----


Date: Mon, 23 Aug 2004 00:34:59 +0930
From: "Craig" <cd-ml at aardvark.net.au>
To: <thelist at lists.evolt.org>
Subject: [thelist] JavaScript onClick question.
Message-ID: <004201c48859$65a8e190$0300a8c0 at FX1>
Content-Type: text/plain;
	charset="iso-8859-1"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Precedence: list
Reply-To: "thelist at lists.evolt.org" <thelist at lists.evolt.org>
Message: 3

Hi,

If I have the following (simplified demo) page. [1]

Here is the code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; =
charset=3Diso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<div onClick=3D"alert('div onClick')">
 <a href=3D"#" onClick=3D"alert('a onClick');return false;">Link</a>
</div>
</body>
</html>

There is a DIV with an onClick alert, and a link with an onClick alert.
What happens is if you click on the Link, the JS alert will popup "a
onClick" and then "div onClick".

How can I make it only popup "a onClick" ??

Thanks for your help.

[1] - http://fx-scripts.com/test/testjs.htm

Regards,
Craig.



------------------------------

_______________________________________________
Help: http://lists.evolt.org/mailman/listinfo/thelist

Archives: http://lists.evolt.org

End of thelist Digest, Vol 18, Issue 46
***************************************




More information about the thelist mailing list