i'm trying to avoid inline event handlers by creating a listener. What i'm trying is based on reading this: http://www.quirksmode.org/js/events_advanced.html
I can't figure out what i'm doing wrong.. here is an example which i want to turn a div's background colour to grey when clicked but it doesn't work :(
I can't figure out what i'm doing wrong.. here is an example which i want to turn a div's background colour to grey when clicked but it doesn't work :(
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head><title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
document.getElementById("box").addEventListener('click',doSomething,false);
function doSomething() {
this.style.backgroundColor = '#555555';
}
</script>
</head>
<body>
<div id="box" style="background-color:blue; height:200px; width:200px;"> </div>
</body>
</html>]
Comment