How do I validate a javascript?
-
03-07-2019 - |
Question
I'm using a small snippet of JS to add a presentational element to my blockquotes (As seen here):
<script type="text/javascript">
$('blockquote.message').append('<span class="arrow" />');
</script>
But the W3C validator hates that crap:
document type does not allow element "span" here
What am I doing wrong? Is there a way to correct this error, while maintaining the function?
Thanks!
Solution
I assume you're using XHTML? You need wrap your JavaScript in CDATA:
<script type="text/javascript">
//<![CDATA[
$('blockquote.message').append('<span class="arrow" />');
//]]>
</script>
See the XHTML reference here: http://xhtml.com/en/xhtml/reference/script/ - "If the script element contains embedded script and that script contains XHTML markup characters such as <, >, & and ", then the script should be enclosed in CDATA"
OTHER TIPS
The blockquote tag can only contain block elements such as P, H1..n, OL/UL, PRE, DL, DIV, NOSCRIPT, BLOCKQUOTE, FORM, HR, TABLE, FIELDSET, ADDRESS