JavaScript: Registrering mouse event over a div element
My first start into JavaScript. I can make mouseover events trigger changes when I use it with images, but not with a div only containing text. What am I doing wrong ? Code follows.
<html>
<head>
<script language="javascript" type="text/javascript">
function addHeading(node, text) {
var newNode=document.createElement("h1");
var text=document.createTextNode(text);
newNode.appendChild(text);
node.appendChild(newNode);
}
</script>
</head>
<body>
<div onmouseover="addHeading(document.body, "Header added")">
Hola!
</div>
</body>
</h开发者_开发技巧tml>
It should be (note the apostrophes):
<div onmouseover="addHeading(document.body, 'Header added')">
otherwise you close the attribute value prematurely. Having that said, it works for me.
精彩评论