I am trying to change the background color of my div element onclick.But it's not working.
<html>
<head>
<title>Event handling5</title>
<meta charset="UTF-8">
<style type="text/css">
.styleClass{
display: table-cell;
border: 5px solid black;
padding: 20px;
text-align: center;
}
</style>
</head>
<body>
<div id="DIV1" class="styleClass">DIV1
<div id="DIV2" class="styleClass">DIV2
<div id="DIV3" class="styleClass">DIV3
</div>
</div>
</div>
<script type="text/javascript">
var divElements=document.getElementsByTagName('div');
for(var i=0;i<divElements;i++){
divElements[i].onclick=function(){
this.style.borderColor='red';
alert(this.getAttribute("id")+"Border color changed");
}
}
</script>
</body>
</html>
Only css functions are working and javascript function is not working.