View Full Version : [SOLVED] simple onmouseover script
friday
11-25-2006, 02:47 PM
Any idea why this doesn't work on IE:
function move(id) {
document.getElementById(id).style.marginTop = "28px";
}
I'm using the function on a li element:
<li onmouseover="move('lijn');" onmouseout="show('lijn');"></li>
BonRouge
11-25-2006, 08:01 PM
Can you show us the page?
friday
11-25-2006, 08:15 PM
This is the HTML page
<?PHP
define("SITEROOT","../");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="robots" content="follow,index"/>
<meta http-equiv="imagetoolbar" content="false"/>
<meta name="MSSmartTagsPreventParsing" content="true"/>
<meta http-equiv="keywords" content=""/>
<meta http-equiv="description" content=""/>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<meta name="abstract" content=""/>
<link rel="shortcut icon" href="<?php echo SITEROOT ?>layout/images/favicon.ico"/>
<link rel="stylesheet" media="screen" href="<?php echo SITEROOT ?>layout/style/style.css" type="text/css"/>
<script type="text/javascript" src="<?php echo SITEROOT ?>layout/code/javascript.js"></script>
</head>
<body>
<div id="container">
<img src="<?php echo SITEROOT ?>layout/images/lijn.gif" width="584" height="2" alt="decorative line" />
<ul id="menu">
<li><a href="#">Home</a></li>
<li onmouseover="hide('lijn');" onmouseout="show('lijn');"><a id="current" href="#">About</a>
<ul>
<li><a href="#">Information</a></li>
<li><a href="#">Video</a></li>
<li class="laatste"><a href="#">Download brochure</a></li>
</ul>
</li>
<li><a href="#">Events</a></li>
<li><a href="#">Press</a></li>
<li class="laatste"><a href="#">Contact</a></li>
</ul>
<img id="lijn" src="<?php echo SITEROOT ?>layout/images/lijn.gif" width="584" height="2" alt="decorative line" />
</div>
</body>
</html>
And here's the javascript:
function hide(id) {
document.getElementById(id).style.marginTop = "28px";
}
function show(id) {
document.getElementById(id).style.marginTop = "0px";
}
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("menu");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
}
node.onmouseout=function() {
this.className=this.className.replace(" over", "");
}
}
}
}
}
window.onload=startList;
steverz
11-25-2006, 08:15 PM
Because you don't assign the li an ID
<li id="lijn"><a href="#">text</a></li>
friday
11-25-2006, 08:18 PM
I'm not trying to move the <li> element, but the <img> below. See the code above, it's this line:
<img id="lijn" src="<?php echo SITEROOT ?>layout/images/lijn.gif" width="584" height="2" alt="decorative line" />
BonRouge
11-25-2006, 08:21 PM
It could be because img is an inline element, so it doesn't take margins.
steverz
11-25-2006, 08:22 PM
In the code you posted the image doesn't have a name either, so which is correct?
steverz
11-25-2006, 08:28 PM
Also <li> element doesn't support those properties, put the onMouseOver="" inside the <a> tag. That should work.
steverz
11-25-2006, 08:31 PM
Tested and works like a charm :)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<script type="text/javascript">
function hide(id) {
document.getElementById(id).style.marginTop = "28px";
}
function show(id) {
document.getElementById(id).style.marginTop = "0px";
}
startList = function() {
if (document.all&&document.getElementById) {
navRoot = document.getElementById("menu");
for (i=0; i<navRoot.childNodes.length; i++) {
node = navRoot.childNodes[i];
if (node.nodeName=="LI") {
node.onmouseover=function() {
this.className+=" over";
}
node.onmouseout=function() {
this.className=this.className.replace(" over", "");
}
}
}
}
}
window.onload=startList;
</script>
</head>
<body>
<div id="container">
<img id="lijn" src="lijn.gif" width="584" height="2" alt="decorative line" />
<ul id="menu">
<li><a href="#">Home</a></li>
<li><a id="current" href="#" onMouseOver="hide('lijn')" onMouseOut="show('lijn')">About</a>
<ul>
<li><a href="#">Information</a></li>
<li><a href="#">Video</a></li>
<li class="laatste"><a href="#">Download brochure</a></li>
</ul>
</li>
<li><a href="#">Events</a></li>
<li><a href="#">Press</a></li>
<li class="laatste"><a href="#">Contact</a></li>
</ul>
<img id="lijn" src="<?php echo SITEROOT ?>layout/images/lijn.gif" width="584" height="2" alt="decorative line" />
</div>
</body>
</html>
friday
11-26-2006, 05:50 AM
Thanks a lot guys.
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.