When is a CDATA section necessary within a script tag?


To avoid parsing the symbols <> &, it is added in <script>…</script>. It is not needed in HTML. Let us see how CDATA is added in <script> tags:

<script>
   //<![CDATA[
      document.write(">");
   //]]>
</script>

Note: CDATA is now deprecated. Do not use.

The CDATA Section interface is used within XML for including extended portions of text. This text is unescaped text, like < and & symbols. These symbols do not want to escape.

It is used like this:

<![CDATA[ ... ]]>

Updated on: 12-Sep-2019

514 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements