createEntityReference (W3C DOM Core method)

Version Depr. Static
DOM1 No No
Browser support (more…)
IE5.5+ FF1.5+ SA3+ OP9.5
Full Buggy Full None


var reference = document.createEntityReference('amp');

The example above creates an entity reference called amp, which would be written in HTML as & and decodes as the entity &.


name (DOMString) required

The name of the entity to reference.


Create an EntityReference node in an XML document, of the specified name.

Return value

The created entity reference node


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 Buggy Buggy Buggy Buggy Buggy Full None None

Opera doesn't implement this method (it returns undefined).

Firefox implements this method but it returns null.

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 Safari 1.3 and 2.

Internet Explorer in HTML doesn't implement this method at all; but there's no reason why it should (because even if it did, it shouldn't work, as per the previous note), so this is not considered a lack of support.


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

User-contributed notes

There are no comments yet.

Related Products