469,311 Members | 2,483 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,311 developers. It's quick & easy.

XHTML DOCTYPE breaks JavaScript x.style.top and x.style.left?

I have the following script (below). If I have the DOCYPE at the top,
tDIV.style.top and tDIV.style.left don't return a value. If I remove the
DOCTYPE from the first line, it works fine and returns and manipulates the
values perfectly.

What could possibly be the relationship? Why would the inclusion of a
DOCTYPE tag at the top of a page break Javascript code?

Browser: Mozilla Firefox. (note: the DOCTYPE on my site is all on one
line, wrapped here for USENET.)

<!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>Title</title>
<link rel="stylesheet" media="screen" href="style.css" title="main"/>
<script type="text/javascript">
<!--
//<![CDATA[
function getLayer(SRC,event){
var IE = document.all?true:false;
var tempX = 0;
var tempY = 0;

var tDIV = document.getElementById(SRC);
tDIV.style.cursor = "hand";
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else { // grab the x-y pos.s if browser is NS
tempX = event.pageX;
tempY = event.pageY;
}
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}
tDIV.style.top = (tempY - 20);
tDIV.style.left = (tempX - 20);
tDIV.style.visibility = "visible";
}

function hideLayer(SRC){
var tDIV = document.getElementById(SRC);
tDIV.style.visibility='hidden';
}
//]]>
-->
</script>
</head>

--
[ Sugapablo ]
[ http://www.sugapablo.net <--personal | http://www.sugapablo.com <--music ]
[ http://www.2ra.org <--political | http://www.subuse.net <--discuss ]

Jul 23 '05 #1
1 2594


Sugapablo wrote:

var tDIV = document.getElementById(SRC); tDIV.style.top = (tempY - 20);
tDIV.style.left = (tempX - 20);


left/top with CSS need a number plus a unit so make that

tDIV.style.top = (tempY - 20) + 'px';
tDIV.style.left = (tempX - 20) + 'px';

The DOCTYPE puts Mozilla in strict mode and then it is picky about
correct CSS values (whether in script or in a stylesheet does not matter).

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

59 posts views Thread by Philipp Lenssen | last post: by
5 posts views Thread by Cruelemort | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.