jQuery Append function causes validation error
jQuery append functi开发者_运维知识库on causes validation error. How to fix it?
append("<span>");
causes Document type does not allow element here
It has nothing to do with jQuery, it's the string in the script that is causing it.
If you are using XHTML, put CDATA tags in the script to keep it from breaking the validation:
<script type="text/javascript">
<![CDATA[
]]>
</script>
Or if the XHTML is served with the content type text/html (which is common):
<script type="text/javascript">
//<![CDATA[
//]]>
</script>
You're being very unclear about when this happens and what validation you are talking about, but I am assuming you are validating the whole document using the W3C validator.
In that case, this has actually nothing to do with jQuery, but with the fact that the validator validates this despite it being in a JavaScript block. I had a similar problem a few months ago, see here.
Edit: @Guffa provides the perfect solution in his answer.
精彩评论