Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving layers part II

Status
Not open for further replies.

james6848

Technical User
May 10, 2004
23
GB
I give up - I just can't get this to work. What elementary mistake am I making?

Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function showlayer() {
	var hiddenlayer = document.getElementById("test");
	var layerposition = parseInt(hiddenlayer.style.left);
	
	if (layerposition < 0) {
		hiddenlayer.style.left = (layerposition + 5) + "px";
		setTimeout("showlayer()", 20);
	}
}
-->
</script>
<style type="text/css">
<!--
#test {
	position: absolute;
	left: -200px;
	top: 0px;
}
-->
</style>
</head>

<body>
<div id="test">
Aaaaaaargh - please work!
</div>
<a href="javascript:showlayer()">Click me</a>

</body>
</html>
 
Don't ask me why this is the case, cause I don't know. But whenever I use id's and classes, I'm unable to change some of those object's attribute values by using javascript. But use style="" instead of class or id, and it works fine:

Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function showlayer() {
    var hiddenlayer = document.getElementById("test");
    var layerposition = parseInt(hiddenlayer.style.left);

    if (layerposition < 0) {
        hiddenlayer.style.left = (layerposition + 5) + "px";
        setTimeout("showlayer()", 20);
    }
}
-->
</script>
</head>

<body>
<div id="test" style="position: absolute;left: -200px;top: 0px;">
Aaaaaaargh - please work!
</div>
<br><br>
<a href="javascript:showlayer()">Click me</a>

</body>
</html>

Rick

 
Hey! It Works! Many thanks, I didn't even consider that that was the prob.

James.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top