9 replies [Last post]
radiant_luv
radiant_luv's picture
User offline. Last seen 1 year 10 weeks ago. Offline
newbie
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
User offline. Last seen 4 days 10 hours ago. Offline
rank Guru
Guru
Timezone: GMT-5
Joined: 2009-10-09
Posts: 2037
Points: 2256

Move the javascript to its

Move the javascript to its own file. Done.

yet again.

Tony
Tony's picture
User offline. Last seen 6 hours 37 min ago. Offline
rank Moderator
Moderator
Timezone: GMT+10
Joined: 2003-03-12
Posts: 3705
Points: 1115

This should help. for (var

This should help.

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

Notice the space before sfEls.length;

Your question may have already been answered, search and read before you ask.

Verschwindende
Verschwindende's picture
User offline. Last seen 4 days 10 hours ago. Offline
rank Guru
Guru
Timezone: GMT-5
Joined: 2009-10-09
Posts: 2037
Points: 2256

Since you're using XHTML, you

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

yet again.

radiant_luv
radiant_luv's picture
User offline. Last seen 1 year 10 weeks ago. Offline
newbie
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
User offline. Last seen 1 year 10 weeks ago. Offline
newbie
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
User offline. Last seen 1 day 10 hours ago. Offline
rank Moderator
Moderator
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8123
Points: 1302

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
User offline. Last seen 9 hours 26 min ago. Offline
rank Moderator
Moderator
Joined: 2004-06-06
Posts: 15095
Points: 2190

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
User offline. Last seen 4 days 10 hours ago. Offline
rank Guru
Guru
Timezone: GMT-5
Joined: 2009-10-09
Posts: 2037
Points: 2256

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.

yet again.

Verschwindende
Verschwindende's picture
User offline. Last seen 4 days 10 hours ago. Offline
rank Guru
Guru
Timezone: GMT-5
Joined: 2009-10-09
Posts: 2037
Points: 2256

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?

yet again.