Click here to get back home

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

 HomeNewsGroups | Search | About
 comp.infosystems.www.authoring.html    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
XHTML DOCTYPE breaks JavaScript x.style.top and x.style.left? Sugapablo 07-05-2005
Posted by Sugapablo on July 5, 2005, 12:58 pm
Please log in for more thread options


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 ]


Posted by Martin Honnen on July 5, 2005, 7:04 pm
Please log in for more thread options




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/

Similar ThreadsPosted
Question about which is the correct style of JavaScript to pass to FORM's onSubmit attribute November 15, 2004, 4:51 pm
not able to operate element's style property in xhtml (but fine in html) January 2, 2007, 3:06 am
tidy ms word output as pure xhtml without css style and font styles July 10, 2007, 5:10 am
TR's w no Style? October 5, 2005, 4:27 pm
style=& ? November 22, 2004, 7:24 am
using vars in div style tag January 5, 2005, 4:32 pm
Footnote style September 25, 2005, 8:38 pm
OL tag with style for decrementing? February 28, 2007, 1:09 am
image alt style pop up for text August 6, 2004, 8:25 am
Style absolute positioning October 25, 2004, 12:14 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap