9 replies [Last post]
radiant_luv
radiant_luv's picture
User offline. Last seen 1 week 6 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: 549
Points: 609

Move the javascript to its

Move the javascript to its own file. Done.

CSSHTMLASP.netC#Coffee

Tony
Tony's picture
User offline. Last seen 1 hour 21 min ago. Offline
rank Moderator
Moderator
Timezone: GMT+10
Joined: 2003-03-12
Posts: 3025
Points: 280

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: 549
Points: 609

Since you're using XHTML, you

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

CSSHTMLASP.netC#Coffee

radiant_luv
radiant_luv's picture
User offline. Last seen 1 week 6 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 1 week 6 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 2 days 4 hours ago. Offline
rank Moderator
Moderator
Timezone: GMT+10
Joined: 2004-05-01
Posts: 7267
Points: 348

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 2 hours 32 min ago. Offline
rank Moderator
Moderator
Joined: 2004-06-06
Posts: 13696
Points: 702

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.

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: 549
Points: 609

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.

CSSHTMLASP.netC#Coffee

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

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?

CSSHTMLASP.netC#Coffee