9 replies [Last post]
radiant_luv
radiant_luv's picture
Offline
newbie
Last seen: 10 years 43 weeks ago
Timezone: GMT+5.5
Joined: 2010-01-30
Posts: 9
Points: 11

Any help to validatie the below code?

Thanks
Radiant_Luv

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>abcd</title>
<link href="css/stylesheet.css" rel="stylesheet" type="text/css" />
 
<script type="text/javascript">
sfHover = function() {
	var sfEls = document.getElementById("mainnav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
</script>
</head>
<body>
</body>
</html>

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 2 weeks 2 days ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2050
Points: 2282

Move the javascript to its

Move the javascript to its own file. Done.

Tony
Tony's picture
Offline
Moderator
Brisbane
Last seen: 1 week 1 day ago
Brisbane
Timezone: GMT+10
Joined: 2003-03-12
Posts: 5343
Points: 2964

This should help. for (var

This should help.

for (var i=0; i &lt; sfEls.length; i++) {

Notice the space before sfEls.length;

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 2 weeks 2 days ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2050
Points: 2282

Since you're using XHTML, you

Since you're using XHTML, you could also delimitate the script by using
<![CDATA[
]]>

radiant_luv
radiant_luv's picture
Offline
newbie
Last seen: 10 years 43 weeks ago
Timezone: GMT+5.5
Joined: 2010-01-30
Posts: 9
Points: 11

it works!

Thanks a lot. It works Smile

Regards
Radiant_Luv

radiant_luv
radiant_luv's picture
Offline
newbie
Last seen: 10 years 43 weeks ago
Timezone: GMT+5.5
Joined: 2010-01-30
Posts: 9
Points: 11

thank you

Verschwindende wrote:

Since you're using XHTML, you could also delimitate the script by using
<![CDATA[
]]>

Thanks a lot. It works Smile

Regards
Radiant_Luv

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 6 years 49 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

Verschwindende wrote: Since

Verschwindende wrote:

Since you're using XHTML, you could also delimitate the script by using
<![CDATA[
]]>

That's only for real XHTML documents: http://perfectionkills.com/optimizing-html/#2_cdata_8230_sections Wink

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 6 years 36 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

And to keep the validator

And to keep the validator happy!

First suggestion earlier was the correct one "Move the javascript to its own file. Done" Where possible scripting should be called in and that obviates the need for that nonsense >{/!--*[[cdata]]}}?> or whatever it's correctly written as.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 2 weeks 2 days ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2050
Points: 2282

Tyssen wrote: That's only for

Tyssen wrote:

That's only for real XHTML documents: http://perfectionkills.com/optimizing-html/#2_cdata_8230_sections Wink

True. True.

Verschwindende
Verschwindende's picture
Offline
Guru
Last seen: 2 weeks 2 days ago
Timezone: GMT-4
Joined: 2009-10-09
Posts: 2050
Points: 2282

Hugo wrote:... First

Hugo wrote:

... First suggestion earlier was the correct one "Move the javascript to its own file. Done" ...

Yes, there really is no point to keep it in the <head>. It obliterates any possibility of caching. Why load something every time when you don't have to?