Escaping HTML in jQuery so it's valid
I've followed advice from firebug and W3C links, however when Firebug confirms all is valid, W3C does not seem to like it and vice versa.
All I'm doing is this:
return '<a href="#"></a>';
I believe I should use a backslash infront of the forward slash, though as XHTML, the start tag needs to be escaped as well? 开发者_开发问答Can anyone shed any light on this.
Thanks.
Short answer: Don't use XHTML on the client.
Almost the short answer: Put your JavaScript in external files
Longer answer: If you really want to embed the JS, then wrap it with CDATA flags
Really long answer: Read http://dorward.me.uk/www/comments-cdata/
If you wrap JS in CDATA tags, you don't need to escape the HTML.
<script type="text/javascript">
/* <![CDATA[ */
function(){
return '<a href="#"></a>';
};
/* ]]> */
</script>
精彩评论