coderef

DOMBaseline · Widely available

The DOM (Document Object Model) API represents HTML and XML documents as trees of nodes. You can use the API to inspect and modify the structure and content of a document.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Jul 29, 2015. Widely available since Jan 29, 2018.

Browser support

DesktopChrome
1+Supportedsince Dec 11, 2008
Current: 155
Edge
12+Supportedsince Jul 29, 2015
Current: 154
Firefox
1+Supportedsince Nov 9, 2004
Current: 157
Safari
1+Supportedsince Jun 23, 2003
Current: 27
MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155
Firefox Android
4+Supportedsince Mar 29, 2011
Current: 157
Safari iOS
1+Supportedsince Jun 29, 2007
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: Attr.

Feature detection

JS · check before using
if ("DOMException" in globalThis) {
  // DOMException is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

Support for each part of the feature (287). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Attr112111841
Attr.localName112111841
Attr.name112111841
Attr.namespaceURI112111841
Attr.ownerElement112111841
Attr.prefix112111841
Attr.value112111841
CDATASection112131841
CharacterData112111841
CharacterData.after54174910544910
CharacterData.appendData112111841
CharacterData.before54174910544910
CharacterData.data112111841
CharacterData.deleteData112111841
CharacterData.insertData112111841
CharacterData.length112111841
CharacterData.nextElementSibling291725929259
CharacterData.previousElementSibling291725929259
CharacterData.remove241223725237
CharacterData.replaceData112111841
Show 267 more
Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
CharacterData.replaceWith54174910544910
CharacterData.substringData112111841
Comment112131841
Comment.Comment291624829248
DOMException112111841
DOMException.DOMException46793710.1463710.3
DOMException.message112111841
DOMException.name112111841
DOMImplementation112111841
DOMImplementation.createDocument112111841
DOMImplementation.createDocumentType112111841
DOMImplementation.createHTMLDocument112411841
DOMStringList11215.11845
DOMStringList.contains1121.55.11845
DOMStringList.item11215.11845
DOMStringList.length11215.11845
DOMTokenList8123.65.11845
DOMTokenList.@@iterator42163610.1423610.3
DOMTokenList.add8123.65.11845
DOMTokenList.add.multiple_parameters241226725267
DOMTokenList.contains8123.65.11845
DOMTokenList.entries42165010.1425010.3
DOMTokenList.forEach42165010.1425010.3
DOMTokenList.item8123.65.11845
DOMTokenList.keys42165010.1425010.3
DOMTokenList.length8123.65.11845
DOMTokenList.remove8123.65.11845
DOMTokenList.remove.multiple_parameters241226725267
DOMTokenList.remove_duplicates60175510605510
DOMTokenList.replace61174910.1614910.3
DOMTokenList.replace.boolean_value67186112676112
DOMTokenList.supports49174910.1494910.3
DOMTokenList.toString8123.65.11845
DOMTokenList.toggle8123.65.11845
DOMTokenList.toggle.force_parameter241224725247
DOMTokenList.trim_whitespace48125110485110
DOMTokenList.value50174710504710
DOMTokenList.values42165010.1425010.3
Document112111841
Document.DOMContentLoaded_event11213.11842
Document.Document601720860208
Document.URL11219318192
Document.activeElement212371847
Document.adoptNode112131841
Document.append54174910544910
Document.body11260118601
Document.characterSet112131841
Document.childElementCount291725929259
Document.children291625929259
Document.compatMode812195.118195
Document.contentType3617193649
Document.createAttribute112111841
Document.createAttributeNS112111841
Document.createCDATASection112111841
Document.createComment112111841
Document.createDocumentFragment112111841
Document.createElement112111841
Document.createElement.options_parameter56795026565026
Document.createElementNS112111841
Document.createElementNS.options_parameter56795026565026
Document.createNodeIterator112131841
Document.createProcessingInstruction112111841
Document.createTextNode112111841
Document.createTreeWalker112131843
Document.createTreeWalker.whatToShow_filter_parameters_optional41312318143
Document.currentScript2912482948
Document.defaultView112111841
Document.dir3612110.136410.3
Document.doctype112111841
Document.documentElement112111841
Document.documentURI117131841
Document.embeds36126110.1366110.3
Document.firstElementChild291725929259
Document.forms11261418613.2
Document.getElementById112111841
Document.getElementsByClassName11233.11842
Document.getElementsByName11258418583.2
Document.getElementsByTagName112111841
Document.getElementsByTagNameNS112111841
Document.hasFocus3412373447
Document.head41261518614
Document.images11261418613.2
Document.implementation112111841
Document.importNode112111841
Document.lastElementChild291725929259
Document.lastModified112141843.2
Document.links11261418613.2
Document.plugins36126110.1366110.3
Document.prepend54174910544910
Document.querySelector1123.53.11842
Document.querySelectorAll1123.53.11842
Document.readyState1123.611841
Document.readystatechange_event91245.11845
Document.referrer112111841
Document.replaceChildren86867814867914
Document.scripts36126110.1366110.3
Document.title112141843.2
DocumentFragment112131841
DocumentFragment.DocumentFragment291724829248
DocumentFragment.append54174910544910
DocumentFragment.childElementCount291725929259
DocumentFragment.children291625929259
DocumentFragment.firstElementChild291725929259
DocumentFragment.getElementById361728936289
DocumentFragment.lastElementChild291725929259
DocumentFragment.prepend54174910544910
DocumentFragment.querySelector2123.541843
DocumentFragment.querySelectorAll2123.541843
DocumentFragment.replaceChildren86867814867914
DocumentType112131841
DocumentType.after54174910544910
DocumentType.before54174910544910
DocumentType.name112131841
DocumentType.publicId112131841
DocumentType.remove241223725237
DocumentType.replaceWith54174910544910
DocumentType.systemId112131841
Element112111841
Element.after54174910544910
Element.append54174910544910
Element.attributes112111841
Element.before54174910544910
Element.childElementCount2123.541843
Element.children1123.541843
Element.classList22163.672547
Element.className2212112541
Element.clientHeight112131841
Element.clientLeft112331841
Element.clientTop112331841
Element.clientWidth112131841
Element.closest411535641359
Element.currentCSSZoom12812812626.412812626.4
Element.firstElementChild2123.541843
Element.getAttribute112111841
Element.getAttributeNS112111841
Element.getAttributeNames61184510.1614510.3
Element.getAttributeNode112111841
Element.getAttributeNodeNS112111841
Element.getBoundingClientRect212341843.2
Element.getClientRects212341843.2
Element.getElementsByClassName11633.11842
Element.getElementsByTagName112111841
Element.getElementsByTagName.all_elements_selector112111841
Element.getElementsByTagNameNS112111841
Element.getElementsByTagNameNS.all_elements_selector112111841
Element.hasAttribute112111841
Element.hasAttributeNS112111841
Element.hasAttributes112111841
Element.id2312112541
Element.innerHTML112111841
Element.insertAdjacentElement11748318481
Element.insertAdjacentHTML117841884
Element.insertAdjacentText11748418484
Element.lastElementChild2123.541843
Element.localName112111841
Element.matches331534833348
Element.namespaceURI112111841
Element.nextElementSibling2123.541843
Element.outerHTML112111.318141
Element.prefix112111841
Element.prepend54174910544910
Element.previousElementSibling2123.541843
Element.querySelector1123.53.11842
Element.querySelectorAll1123.53.11842
Element.remove241223725237
Element.removeAttribute112111841
Element.removeAttributeNS112111841
Element.removeAttributeNode112111841
Element.replaceChildren86867814867914
Element.replaceWith54174910544910
Element.setAttribute112111841
Element.setAttributeNS112111841
Element.setAttributeNode112111841
Element.setAttributeNodeNS112111841
Element.tagName112111841
Element.toggleAttribute69186312696312
HTMLCollection112111841
HTMLCollection.item112111841
HTMLCollection.length112111841
HTMLCollection.namedItem112111841
HTMLDocument112111841
HTMLElement112111841
HTMLElement.dir112131841
HTMLElement.error_event112111841
HTMLElement.hidden61245.11845
HTMLElement.innerText11245118451
HTMLElement.load_event11211.31841
HTMLElement.offsetHeight112131841
HTMLElement.offsetLeft112131841
HTMLElement.offsetParent112131841
HTMLElement.offsetTop112131841
HTMLElement.offsetWidth112131841
HTMLElement.outerText112981.318981
NamedNodeMap11234118341
NamedNodeMap.getNamedItem11234118341
NamedNodeMap.getNamedItemNS11234118341
NamedNodeMap.item11234118341
NamedNodeMap.length11234118341
NamedNodeMap.removeNamedItem11234118341
NamedNodeMap.removeNamedItemNS11234118341
NamedNodeMap.setNamedItem11234118341
NamedNodeMap.setNamedItemNS11234118341
Node112111841
Node.appendChild11211.11841
Node.baseURI1121≤41841
Node.childNodes11211.21841
Node.cloneNode11211.11841
Node.compareDocumentPosition212141843.2
Node.contains161291.11891
Node.firstChild112111841
Node.hasChildNodes112111841
Node.insertBefore11211.11841
Node.isDefaultNamespace112131841
Node.isEqualNode112131841
Node.isSameNode11248318481
Node.lastChild1121118451
Node.lookupNamespaceURI112131841
Node.lookupPrefix112131841
Node.nextSibling11211.11841
Node.nodeName112111841
Node.nodeType11211.11841
Node.nodeValue112111841
Node.normalize112111841
Node.ownerDocument112111841
Node.parentElement11291.11891
Node.parentNode11211.11841
Node.previousSibling112111841
Node.removeChild11211.11841
Node.replaceChild11211.11841
Node.textContent112131841
NodeIterator1123.531843
NodeIterator.filter1123.531843
NodeIterator.nextNode1123.531843
NodeIterator.pointerBeforeReferenceNode1173.531843
NodeIterator.previousNode1123.531843
NodeIterator.referenceNode1173.531843
NodeIterator.root1123.531843
NodeIterator.whatToShow1123.531843
NodeList112111841
NodeList.@@iterator51793610513610
NodeList.entries51165010515010
NodeList.forEach51165010515010
NodeList.item112111841
NodeList.keys51165010515010
NodeList.length112111841
NodeList.values51165010515010
ProcessingInstruction112111841
ProcessingInstruction.doc_xml112111841
ProcessingInstruction.target112111841
Text112111841
Text.Text291624829248
Text.splitText112111841
Text.wholeText2123.541843.2
TreeWalker112431843
TreeWalker.currentNode112431843
TreeWalker.filter112431843
TreeWalker.firstChild112431843
TreeWalker.lastChild112431843
TreeWalker.nextNode112431843
TreeWalker.nextSibling112431843
TreeWalker.parentNode112431843
TreeWalker.previousNode112431843
TreeWalker.previousSibling112431843
TreeWalker.root112431843
TreeWalker.whatToShow112431843
Window.document112111841
XMLDocument341211034410