Re: Javascript and CSS questions

by Andrew McFarland <aamcf(at)aamcf.co.uk>

 Date:  Sat, 12 Oct 2002 21:30:26 +0100
 To:  <hwg-techniques(at)hwg.org>
 In-Reply-To:  telus
  todo: View Thread, Original
At 12:37 12/10/02 -0700, Susan Friesen wrote:
<snip/>
>I consider myself a rookie at javascript and I'm having difficulty
>validating this page: http://www.investinakinderworld.com/index_test.shtml
<snip/>

JavaScript makes validation complex.

What is happening is the first time </a appears in the script the script 
element is closed, at least from the point of view of a SGML parser. This 
is why you get the validation errors for the 2nd, 3rd, 4th, and 5th </a>s 
in the script, but not the first. (To see this `in action', run the page 
through the W3 validator and check the `Show Parse tree' option. This 
displays the page in the way that the validator `sees' it.)

IMO, the best way to solve this is to use an external JavaScript file. 
Alternatively, you could make sure all your script elements begin with <!-- 
and end with // -->, but this is a fairly nasty hack which will cause you 
problems in some circumstances.[1]

See also http://www.htmlhelp.com/tools/validator/problems.html

Andrew

[1] Specifically, if you use this in a page that is parsed as XML the 
entire script will be hidden. This will be an issue in a few years time.

--
http://aamcf.co.uk/

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA