I'm in the process of learning a bit of web programming, and I'm making
an effort to stay compliant with current web standards. I have a
minimal web page with divs intended to change colour when the mouse
rolls over them, but despite the fact that the page validates as XHTML,
it doesn't work in either IE6 or Firefox. Am I making an obvious
mistake?
The HTML file is as follows:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<title>test.com</title>
<link rel='stylesheet' href='css/index.css' type='text/css'
title='Standard' />
</head>
<body>
<script src='script/index.js' type='text/javascript'></script>
<div id='container'>
<div
id='browse'
class='inactive'
onmouseover='setAttribute("browse", "class", "active")'
onmouseout='setAttribute("browse", "class", "inactive")'
Browse</div> <div
id='search'
class='inactive'
onmouseover='setAttribute("search", "class", "active")'
onmouseout='setAttribute("search", "class", "inactive")'Search</div> <div
id='post'
class='inactive'
onmouseover='setAttribute("post", "class", "active")'
onmouseout='setAttribute("post", "class", "inactive")'Post</div> <div
id='members'
class='inactive'
onmouseover='setAttribute("members", "class", "active")'
onmouseout='setAttribute("members", "class", "inactive")'Log In</div>
</div>
</body>
</html>
And the associated script/index.js script is as follows:
// set the selected element's class
function setAttribute(id, attr, val) {
// get the element and set its class
document.getElementById(id).setAttribute(attr, val);
}
What's going wrong? It appears that the function setAttribute() is not
being called. I've tried embedding the function definition in the HTML
page itself but this makes no difference. Replacing the function calls
with an "alert('bob');" works perferctly, so it appears my problem lies
with the function definition/call.
Thanks in advance for any help anyone can give me!
Keith