开发者

W3C Markup Validation errors with jQuery

开发者 https://www.devze.com 2022-12-24 03:38 出处:网络
Running a validat开发者_开发技巧ion on my pages where I used jQuery gives me lots of errors.. I escaped the closing tags but keep getting errors.

Running a validat开发者_开发技巧ion on my pages where I used jQuery gives me lots of errors.. I escaped the closing tags but keep getting errors.

<script type="text/javascript">
    $(document).ready(function() {
        $("#main").html('<p>hello world<\/p>'); 
    });
</script>


Assuming you use XHTML as DOCTYPE you should wrap js-code which contains HTML fragments with CDATA

<script type="text/javascript">
    $(document).ready(function() {
        /*<![CDATA[*/
        $("#main").html('<p>hello world</p>');
        /*]]>*/
    });
</script>

Why?: Mozilla Dev: Properly Using CSS and JavaScript in XHTML Documents


Do this:

<script type="text/javascript">
//<![CDATA[
    $(document).ready(function() {
        $("#main").html('<p>hello world</p>'); 
    });
//]]>
</script>

You can read a bit more on the topic here. The basics are that Javascript tags are CDATA elements normally, PCDATA with XHTML (so it looks inside), to be safe they need to be marked up in this way.

0

精彩评论

暂无评论...
验证码 换一张
取 消