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

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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">
    <link rel="stylesheet" media="screen" href="style.css" title="main"/>
<script type="text/javascript">
    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);

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

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

Sugapablo wrote:

Quoted text here. Click to load it

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 /

Site Timeline