Re: Incorrect error reported in Javascript

On 26 Oct 2014, at 21:39, Arjan den Boer wrote:

> /Line 37, Column 209/: end tag for element "A" which is not open
>
> |...g id='tn"+j+"' class='"+cn+"' 
> src='thumbnail.php?sqz=90&img="+imgs[j]+"'></a*>*"}
>
> |
>
> This is in the HEAD section of the document and within <script 
> ...><!-- and --></script> tags.
> Why is the validator checking to-be-generated-HTML within a 
> javascript, even within comment <!--/--> tags?

They aren't comments. The content of a script element is defined as 
CDATA so markup doesn't have its usual meaning. The token `</` cannot 
appear inside an element defined that way.

Use <\/a> if you need to represent an HTML end tag in a JavaScript 
string.

(The comments are only treated as such by browsers that don't recognise 
script tags, it is a hack to stop the JavaScript being rendered as text 
in Netscape 1 era browsers. Those browsers aren't used any more so 
wrapping a script with comments is pointless)



-- 
David Dorward
http://dorward.co.uk/

Received on Wednesday, 29 October 2014 22:36:50 UTC