createCDATASection (W3C DOM Core method)

Spec
Version Depr. Static
DOM1 No No
Browser support (more…)
IE5.5+ FF1.5+ SA3+ OP9+
Full Full Full Buggy
Returns
CDATASection
Throws
NOT_SUPPORTED_ERR

Example

var cdata = document.createCDATASection
    ('<p>Good relations have I with the Wookies</p>');

element.appendChild(cdata);

The example above creates a CDATASection node with the data <p>Good relations have I with the Wookies</p>, then adds it to an element using appendChild.

So if the element in question were an empty RSS <description> element:

<description></description>

Then the operation above would result in this

<description><![CDATA[<p>Good relations have I with the Wookies</p>]]></description>

Arguments

data (DOMString) required

The data for the CDATA section.

Description

Create a CDATASection node in an XML document, with the specified data.

The created CDATA section can then be added to the document using Node methods such as appendChild or insertBefore.

Return value

The created CDATA section node.

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Full Full Full Full Full Full Buggy Buggy Full Buggy Buggy

The specification says that this method should throw a DOMException in HTML mode1 (code 9: NOT_SUPPORTED_ERR). Therefore if a browser supports it and does not throw an exception in that mode, this is considered a bug, and is what happens in Opera and Safari 1.3 and 2.

: This doesn’t - and needn’t - work for Internet Explorer in HTML

In Internet Explorer in HTML this method is not implemented (it returns undefined). Similarly to the previous note, this cannot be considered a bug or lack of support because CDATASection is an XML construct.

Footnotes

1 On XHTML or HTML pages served as text/html.

User-contributed notes

There are no comments yet.

Related Products