5

I have this working piece of javascript:

<script type="text/javascript">
    //<![CDATA[
        jQuery(document).ready(function() {
            jQuery("#page_template option[value='sidebar-page.php']").remove();
        });
    //]]>
</script>

What's //<![CDATA[ and //]]> stand for? I never used it but lately I meet it very often. Thank you guys in advance for increasing my knowledge! ;)

AlexWebLab
  • 846
  • 3
  • 15
  • 29
  • The CDATA tags here have been commented out, so surely they would have no effect here? So I don't understand why this question has been marked as a duplicate. – Colin 't Hart Nov 05 '14 at 13:11

1 Answers1

4

CDATA is used to allow the document to be loaded as straight XML. You can embed JS in XML documents without replacing special XML characters like <, >, &, etc by XML entities &lt;, &gt;, &amp; etc to prevent that the XML syntax get corrupted.

So double slash // in your XML will be treated as text instead of a comment and hence it makes CDATA as an XML tag.

The wiki says that:-

In an XML document or external parsed entity, a CDATA section is a section of element content that is marked for the parser to interpret as only character data, not markup. A CDATA section is merely an alternative syntax for expressing character data; there is no semantic difference between character data that manifests as a CDATA section and character data that manifests as in the usual syntax in which < and & would be represented by < and &, respectively.

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331