473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 24 '05 #1
1 32811


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 24 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: mike | last post by:
regards: I use Jtidy (api) to translate a HTML file into a "XHTML file". But The "XHTML file" cannot be identified by nokia 6600. Do I miss something important? Or this is Jtidy's weakness or...
59
by: Philipp Lenssen | last post by:
I've tested some of the new Nokia 6600 functionality. It ships with WAP2 and XHTML Support (it says). What it does is check the Doctype -- if it's not the XHTML Mobile Profile Doctype, but a...
7
by: Paul Marsh | last post by:
Hello everyone, I am attempting to create a xhtml page that uses a bit of dhtml. The javascript I am using uses document.getElementById('someId').style.someProperty; and is and external script....
1
by: Sugapablo | last post by:
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...
7
by: hawat.thufir | last post by:
Given an xhtml file, how can I "export" the data to plain-text? That is, I want: google www.google.com Whereas, if I copy and paste what the browser shows, I lose the URL and end up with:...
6
by: reynard | last post by:
I have a page that uses this doctype <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> but when I change to this: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
15
by: Lennart | last post by:
Hi folks, I have created an animated image gallery in dhtml. It works fine in Internet Explorer. In Firefox, it only works if I ommit the DOCTYPE tag. The page is valid xhtml-strict but with a...
0
by: Zhang Weiwu | last post by:
Hello. I am pretty sure this problem has been mentioned somewhere else but I wasn't able to google it out yet. I have two pages, in xhtml and in html, they do the same thing: create a table cell...
5
by: Cruelemort | last post by:
All, I ran into a CSS problem when using the XHTML 1.0 transitional document type, so i have made a simplified version to show you all here. Basically i have written a very simple HTML page...
14
by: tader | last post by:
so i got script like that <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Drag and Drop</title> <style> #slater { display:block;
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.