9 replies [Last post]
radiant_luv
radiant_luv's picture
User offline. Last seen 26 weeks 3 days ago. Offline
newbie
Timezone: GMT+5.5
Joined: 2010-01-30
Posts: 3
Points: 4

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 is online Online
rank Leader
Leader
Timezone: GMT-4
Joined: 2009-10-09
Posts: 748
Points: 838

Move the javascript to its

Move the javascript to its own file. Done.

CSS HTML ASP.net C# Coffee

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

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 is online Online
rank Leader
Leader
Timezone: GMT-4
Joined: 2009-10-09
Posts: 748
Points: 838

Since you're using XHTML, you

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

CSS HTML ASP.net C# Coffee

radiant_luv
radiant_luv's picture
User offline. Last seen 26 weeks 3 days ago. Offline
newbie
Timezone: GMT+5.5
Joined: 2010-01-30
Posts: 3
Points: 4

it works!

Thanks a lot. It works Smile

Regards
Radiant_Luv

radiant_luv
radiant_luv's picture
User offline. Last seen 26 weeks 3 days ago. Offline
newbie
Timezone: GMT+5.5
Joined: 2010-01-30
Posts: 3
Points: 4

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 7 hours 25 min ago. Offline
rank Moderator
Moderator
Timezone: GMT+10
Joined: 2004-05-01
Posts: 7411
Points: 509

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, post ALL your code, both HTML & CSS. No server-side code; just the code sent to the browser.
Use tags.
My articles | CSS Reference

Hugo
Hugo's picture
User offline. Last seen 4 hours 34 min ago. Offline
rank Moderator
Moderator
Timezone: GMT+1
Joined: 2004-06-06
Posts: 14200
Points: 1256

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 is online Online
rank Leader
Leader
Timezone: GMT-4
Joined: 2009-10-09
Posts: 748
Points: 838

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.

CSS HTML ASP.net C# Coffee

Verschwindende
Verschwindende's picture
User is online Online
rank Leader
Leader
Timezone: GMT-4
Joined: 2009-10-09
Posts: 748
Points: 838

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?

CSS HTML ASP.net C# Coffee