Stephen Brown
Stephen Brown

Reputation: 574

Validate Script tag within XHTML

The "span" tag is invalid, how do I make it valid?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

...

<script type="text/javascript">
  var locations = [
    [
      'Kirklevington Village Hall',
      '<span style="font-size:2;"><b>Kirklevington Village Hall</b>,<br />Forest Lane,<br />Kirklevington,<br />Stockton&nbsp;on&nbsp;tees,<br />TS15&nbsp;9LX</span>',
      54.4825,
      -1.33663
    ]
  ];
</script>

Upvotes: 0

Views: 87

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201538

The simplest way is to put the script code to a separate file, say foo.js, and refer to it using <script "src=foo.js" type="text/javascript"></script>. Other methods involve various techniques for “escaping” the content of the script element, and they are clumsy and error-prone.

The XHTML 1.0 spec, appendix C, recommends: “Use external scripts if your script uses < or & or ]]> or --.”

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

Enclose your script in <![CDATA[ and ]]> to make it appear as a comment to the validator.

More info here

Upvotes: 2

Related Questions