Click to See Complete Forum and Search --> : Help pls onclick()


trx314
04-29-2006, 07:00 AM
It look like I'm missing something, what is wrong with that - it's not working:

<html>
<head>
<style type="text/css">
#test {
height: 100px; width: 100px; border: 1px solid #000000;
}
</style>
</head>
<body>
<div id="test">Content for class "test" Goes Here</div>
<script language="javascript">
document.getElementById('test').onClick = alert('yahooo');
</script>
</body>
</html>

Thank you for your cooperation

Fang
04-29-2006, 07:50 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>add event</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script type="text/javascript">
window.onload=function() { // wait untill all loaded
if(document.getElementById('test')) { // test for existence
document.getElementById('test').onclick = function() {alert('yahooo');};
}
}
</script>

<style type="text/css">
#test {
height: 100px; width: 100px; border: 1px solid #000000;
}
</style>

</head>
<body>
<div id="test">Content for class "test" Goes Here</div>
</body>
</html>

trx314
04-29-2006, 07:24 PM
10x Pal, it is working fine.

felgall
04-30-2006, 03:57 PM
Javascript is case sensitive so you need to make sure that all event handler references (eg. onclick) are specified in all lowercase.