Contact Form

Name

Email *

Message *

Cari Blog Ini

Cdata Javascript

Web Development Tips: Using CDATA in HTML

What is CDATA?

CDATA, which stands for Character Data, is a construct used in XML to indicate that a section of text should be interpreted as raw data, rather than as HTML or XML markup. This is useful for including scripts or other code within an XML document without having to worry about the code being interpreted as markup.

Using CDATA in HTML

While CDATA is primarily used in XML, it can also be used in HTML to prevent the JavaScript engine from interpreting the CDATA and marks you can wrap them in comments If your script does not contain any.

To use CDATA in HTML, simply wrap the text you want to be interpreted as raw data in the following tags:

<!CDATA[ Your text here ]>

For example, the following code would prevent the JavaScript engine from interpreting the text "Hello, world!" as a script:

<!CDATA[ Hello, world! ]>

Conclusion

CDATA is a useful construct for including scripts or other code within an XML or HTML document without having to worry about the code being interpreted as markup. By using CDATA, you can ensure that your code will be executed as intended.


Comments