Quick Reference
This is a quick reference list of JavaScript DOM methods and properties with examples of how they are used.
- JavaScript – DOM attributes.length PropertyThe attributes.length property returns the number of nodes in a NamedNodeMap.
- JavaScript – DOM Attributes name PropertyThe Attributes name property returns the name of an attribute.
- JavaScript – DOM Collection item() MethodThe collection item() method returns the element at a specified index in an HTMLCollection, which is an array-like list of HTML elements.
- JavaScript – DOM Collection length PropertyThe Collection length property returns the number of elements in an HTMLCollection, which is an array-like list of HTML elements.
- JavaScript – DOM Collection namedItem() MethodThe collection namedItem() method returns a named element from an HTMLCollection, which is an array-like list of HTML elements.
- JavaScript – DOM document.activeElement PropertyThe document.activeElement property returns the HTML element that has focus.
- JavaScript – DOM document.addEventListener() MethodThe document.addEventListener() method attaches an event handler to a document.
- JavaScript – DOM document.adoptNode() MethodThe document.adoptNode() method adopts a node from another document.
- JavaScript – DOM document.baseURI PropertyThe document.baseURI property returns the base URI of the document.
- JavaScript – DOM document.body PropertyThe document.body property returns the document’s <body> element.
- JavaScript – DOM document.characterSet PropertyThe document.characterSet property returns the character encoding for the document.
- JavaScript – DOM document.close() MethodThe document.close() method closes a document previously opened with the open() method.
- JavaScript – DOM document.cookie PropertyThe document.cookie property returns a semicolon-separated list of key=value pairs (document cookies).
- JavaScript – DOM document.createAttribute() MethodThe document.createAttribute() method creates an attribute and returns the attribute as an Attr object.
- JavaScript – DOM document.createComment() MethodThe document.createComment() method creates a comment and returns the comment node.
- JavaScript – DOM document.createDocumentFragment() MethodThe document.createDocumentFragment() method creates a new document fragment that can be inserted into any document.
- JavaScript – DOM document.createElement() MethodThe document.createElement() method creates an element node.
- JavaScript – DOM document.createEvent() MethodThe document.createEvent() method creates an event object.
- JavaScript – DOM document.createTextNode() MethodThe document.createTextNode() method creates a text node.
- JavaScript – DOM document.defaultView PropertyThe document.defaultView property returns the document’s window object.
- JavaScript – DOM document.designMode PropertyThe document.designMode property sets or returns if the document is editable.
- JavaScript – DOM document.doctype PropertyThe document.doctype property returns a document’s doctype object. And doctype.name returns the name of the doctype.
- JavaScript – DOM document.documentElement PropertyThe document.documentElement property returns a document’s element object.
- JavaScript – DOM document.documentURI PropertyThe document.documentURI property sets or returns a document’s location.
- JavaScript – DOM document.domain PropertyThe document.domain property returns the domain name of the server the document was loaded from.
- JavaScript – DOM document.embeds PropertyThe document.embeds property returns a collection of all <embed> elements in the document.
- JavaScript – DOM document.forms PropertyThe document.forms property returns a collection of all <form> elements in a document.
- JavaScript – DOM document.hasFocus() MethodThe document.hasFocus() method returns “true” if the document, or any element in the document, has focus. Otherwise it returns “false”.
- JavaScript – DOM document.head PropertyThe document.head property returns the <head> element of the document.
- JavaScript – DOM document.images PropertyThe document.images property returns a collection of all <img> elements in a document.
- JavaScript – DOM document.importNode() MethodThe document.importNode() method imports a node from another document, and with the second parameter set to true, will also import child nodes.
- JavaScript – DOM document.lastModified PropertyThe document.lastModified property returns the date and time the document was last modified.
- JavaScript – DOM document.links PropertyThe document.links property returns a collection of all links (<a> and <area> elements) in the document.
- JavaScript – DOM document.normalize() MethodThe document.normalize() method removes empty text nodes, and joins adjacent text nodes.
- JavaScript – DOM document.open() MethodThe document.open() method opens a document for writing.
- JavaScript – DOM document.readyState PropertyThe document.readyState property returns the loading status of the current document.
- JavaScript – DOM document.referrer PropertyThe document.referrer property returns the URL of the document that loaded the current document.
- JavaScript – DOM document.removeEventListener() MethodThe document.removeEventListener() method removes an event handler from a document.
- JavaScript – DOM document.scripts PropertyThe document.scripts property returns a collection of all <script> elements in the document.
- JavaScript – DOM document.title PropertyThe document.title property sets or returns the title of the document.
- JavaScript – DOM document.URL PropertyThe document.URL property returns the full URL of the document.
- JavaScript – DOM document.write() MethodThe document.write() method writes directly to an open HTML document.
- JavaScript – DOM document.writeln() MethodThe document.writeln() method writes directly to an open HTML document, with the addition of writing a newline character after each statement.
- JavaScript – DOM Element addEventListener() MethodThe Element addEventListener() method attaches an event handler to an element.
- JavaScript – DOM Element appendChild() MethodThe Element appendChild() method appends an element as the last child of a parent element.
- JavaScript – DOM Element attributes PropertyThe Element attributes property returns a collection of attributes in an element.
- JavaScript – DOM Element blur() MethodThe Element blur() method removes focus from an element.
- JavaScript – DOM Element childElementCount PropertyThe Element childElementCount property returns the number of child elements of an element.
- JavaScript – DOM Element childNodes PropertyThe Element childNodes property returns a list of an elements’s child nodes.
- JavaScript – DOM Element children PropertyThe Element children property returns a list of an element’s child elements.
- JavaScript – DOM Element classList PropertyThe Element classList property returns the CSS classnames of an element.
- JavaScript – DOM Element className PropertyThe Element className property sets or returns an element’s class attribute.
- JavaScript – DOM Element click() MethodThe Element click() method simulates a mouse-click on an element.
- JavaScript – DOM Element clientHeight PropertyThe Element clientHeight property returns the viewable height of an element, including padding, but not the border, scrollbar or margin.
- JavaScript – DOM Element clientLeft PropertyThe Element clientLeft property returns the width of the element’s left border not including the element’s left padding or left margin.
- JavaScript – DOM Element clientTop PropertyThe Element clientTop property returns the width of the element’s top border not including the element’s top padding or top margin.
- JavaScript – DOM Element clientWidth PropertyThe Element clientWidth property returns the viewable width of an element, including padding, but not the border, scrollbar or margin.
- JavaScript – DOM Element cloneNode() MethodThe Element cloneNode() method creates a copy of a node (and all its attributes and their values), and returns the clone.
- JavaScript – DOM Element closest() MethodThe Element closest() method searches up the DOM tree (the element and then its ancestors) for elements which matches a specified CSS selector.
- JavaScript – DOM Element compareDocumentPosition() MethodThe Element compareDocumentPosition() method compares two nodes, and returns an integer describing where they are positioned in the document.
- JavaScript – DOM Element contains() MethodThe Element contains() method returns “true” if a node is a descendant of a node, and returns “false” if it’s not.
- JavaScript – DOM Element contentEditable PropertyThe Element contentEditable property sets or returns if the content of an element is editable.
- JavaScript – DOM Element dir PropertyThe Element dir property sets or returns an elements’s dir attribute, which specifies the text-direction.
- JavaScript – DOM Element focus() MethodThe Element focus() method gives focus to an element if it can receive focus.
- JavaScript – DOM Element firstChild PropertyThe Element firstChild property returns the first child node of a node.
- JavaScript – DOM Element firstElementChild PropertyThe Element firstElementChild property returns the first child element of the specified element.
- JavaScript – DOM Element getAttribute() MethodThe Element getAttribute() method returns the value of an element’s attribute.
- JavaScript – DOM Element getAttributeNode() MethodThe Element getAttributeNode() method returns an element’s attribute.
- JavaScript – DOM Element getBoundingClientRect() MethodThe Element getBoundingClientRect() method returns the size of an element, and its position relative to the viewport.
- JavaScript – DOM Element getElementsByClassName() MethodThe Element getElementsByClassName() method returns a collection of child elements with a given class name.
- JavaScript – DOM Element getElementsByTagName() MethodThe Element getElementsByClassName() method returns a collection of child elements with a given tag name.
- JavaScript – DOM Element hasAttribute() MethodThe Element hasAttribute() method returns “true” if the attribute exists, and “false” if it does not exist.
- JavaScript – DOM Element hasAttributes() MethodThe Element hasAttributes() method returns “true” if a node has attributes, and “false” if it does not.
- JavaScript – DOM Element hasChildNodes() MethodThe Element hasChildNodes() method returns “true” if the specified node has any child nodes, and “false” if it does not have any child nodes.
- JavaScript – DOM Element id PropertyThe Element id property sets or returns the value of an element’s id attribute.
- JavaScript – DOM Element innerHTML PropertyThe Element innerHTML property sets or returns the HTML content of an element.
- JavaScript – DOM Element innerText PropertyThe Element innerText property sets or returns the text content of an element.
- JavaScript – DOM Element insertAdjacentElement() MethodThe Element insertAdjacentElement() method inserts an element into a specified position.
- JavaScript – DOM Element insertAdjacentHTML() MethodThe Element insertAdjacentHTML() method inserts HTML code into a specified position.
- JavaScript – DOM Element insertAdjacentText() MethodThe Element insertAdjacentText() method inserts text into a specified position.
- JavaScript – DOM Element insertBefore() MethodThe Element insertBefore() method inserts a child node before an existing child node.
- JavaScript – DOM Element isContentEditable PropertyThe Element isContentEditable property returns “true” if the content of an element is editable, and “false” if it is not editable.
- JavaScript – DOM Element isDefaultNamespace() MethodThe Element isDefaultNamespace() method returns “true” if the elements’s namespace is default, and “false” if it is not.
- JavaScript – DOM Element isEqualNode() MethodThe Element isEqualNode() returns true if two elements are equal.
- JavaScript – DOM Element isSameNode() MethodThe Element isSameNode() method checks if two nodes are the same node, returning “true” if the two nodes are the same node, and “false” if not.
- JavaScript – DOM Element lang PropertyThe Element lang property returns the value of an element’s lang attribute.
- JavaScript – DOM Element lastChild PropertyThe Element lastChild property returns the last child node of a node.
- JavaScript – DOM Element lastElementChild PropertyThe Element lastElementChild property returns the last child element of an element.
- JavaScript – DOM Element namespaceURI PropertyThe Element namespaceURI property returns the URI of an element’s namespace.
- JavaScript – DOM Element matches() MethodThe Element matches() method returns true if an element matches a specific CSS selector or selectors.
- JavaScript – DOM Element nextElementSibling PropertyThe Element nextElementSibling property returns the next element in the same tree level.
- JavaScript – DOM Element nextSibling PropertyThe Element nextSibling property returns the next node on the same tree level.
- JavaScript – DOM Element nodeName PropertyThe Element nodeName property returns the name of a node.
- JavaScript – DOM Element nodeType PropertyThe Element nodeType property returns the node type, as a number, of the specified node.
- JavaScript – DOM Element nodeValue PropertyThe Element nodeValue property returns the value of a node. If the node is an element node, the nodeValue property will return null.
- JavaScript – DOM Element normalize() MethodThe Element normalize() method removes empty text nodes, and joins adjacent text nodes.
- JavaScript – DOM Element offsetHeight PropertyThe Element offsetHeight property returns the viewable height of an element, including padding, border and scrollbar, but not the margin.
- JavaScript – DOM Element offsetLeft PropertyThe Element offsetLeft property returns the left position relative to the parent.
- JavaScript – DOM Element offsetParent PropertyThe Element offsetParent property returns the nearest ancestor that has a position other than static. It return “null” if set to display: none;.
- JavaScript – DOM Element offsetWidth PropertyThe Element offsetWidth property returns the viewable width of an element, including padding, border and scrollbar, but not the margin.
- JavaScript – DOM Element offsetTop PropertyThe Element offsetTop property returns the top position relative to the parent.
- JavaScript – DOM Element outerHTML PropertyThe Element outerHTML property sets or returns the HTML element, including attributes, the start tag, and the end tag.
- JavaScript – DOM Element outerText PropertyThe Element outerText property sets or returns the text content of the specified node.
- JavaScript – DOM Element ownerDocument PropertyThe Element ownerDocument property returns the owner document of a node, as a Document object.
- JavaScript – DOM Element parentElement PropertyThe Element parentElement property returns the parent element of the specified element.
- JavaScript – DOM Element parentNode PropertyThe JavaScript Element parentNode property returns the parent node of an element or node.
- JavaScript – DOM Element previousSibling PropertyThe Element previousSibling property returns the previous node on the same tree level.
- JavaScript – DOM Element previousElementSibling PropertyThe Element previousElementSibling property returns the previous element in the same tree level.
- JavaScript – DOM Element querySelector() MethodThe Element querySelector() method returns the first child element that matches the specified CSS selector or selectors of an element.
- JavaScript – DOM Element querySelectorAll() MethodThe Element querySelectorAll() method returns an element’s child elements, as a static NodeList object, that match specified CSS selectors.
- JavaScript – DOM Element remove() MethodThe Element remove() method removes an element or node from the document.
- JavaScript – DOM Element removeAttribute() MethodThe Element removeAttribute() method removes an attribute from an element.
- JavaScript – DOM Element removeAttributeNode() MethodThe Element removeAttributeNode() method removes an attribute from an element.
- JavaScript – DOM Element removeChild() MethodThe Element removeChild() method removes an element’s child.
- JavaScript – DOM Element removeEventListener() MethodThe Element removeEventListener() method removes an event handler to an element.
- JavaScript – DOM Element replaceChild() MethodThe Element replaceChild() method replaces a child node with a new node.
- JavaScript – DOM Element scrollHeight PropertyThe Element scrollHeight property returns the height of an element including padding, but excluding borders, scrollbars, or margins.
- JavaScript – DOM Element scrollIntoView PropertyThe Element scrollIntoView() method scrolls an element into the visible area of the browser window.
- JavaScript – DOM Element scrollLeft PropertyThe Element scrollLeft property sets or returns the number of pixels an element’s content is scrolled horizontally.
- JavaScript – DOM Element scrollTop PropertyThe Element scrollTop property sets or returns the number of pixels an element’s content is scrolled vertically.
- JavaScript – DOM Element scrollWidth PropertyThe Element scrollWidth property returns the width of an element including padding, but excluding borders, scrollbars, or margins.
- JavaScript – DOM Element setAttribute() MethodThe Element setAttribute() method sets a value for an attribute.
- JavaScript – DOM Element setAttributeNode() MethodThe Element setAttributeNode() method adds an attribute node to an element, replacing existing attribute nodes.
- JavaScript – DOM Element style PropertyThe Element style property sets or returns the values of an element’s style attribute.
- JavaScript – DOM Element tabIndex PropertyThe Element tabIndex property sets or returns the value of the tabindex attribute of an element.
- JavaScript – DOM Element tagName PropertyThe Element tagName property returns the tag name of an element in UPPERCASE.
- JavaScript – DOM Element textContent PropertyThe Element textContent property sets or returns the text content of the specified node and all its descendants.
- JavaScript – DOM Element title PropertyThe Element title property sets or returns the value of an element’s title attribute.
- JavaScript – DOM NodeList entries() MethodThe NodeList entries() method returns an iterator with the key/value pairs from a NodeList, which is an array-like list of Node Objects.
- JavaScript – DOM NodeList forEach() MethodThe NodeList forEach() method executes a callback function for each node in a NodeList, which is an array-like list of Node Objects.
- JavaScript – DOM NodeList item() MethodThe NodeList item() method returns the node at a specified index in a NodeList, which is an array-like list of Node Objects.
- JavaScript – DOM NodeList keys() MethodThe NodeList keys() method returns an iterator with the keys from a NodeList, which is an array-like list of Node Objects.
- JavaScript – DOM NodeList length PropertyThe NodeList length property returns the number of nodes in a NodeList, which is an array-like list of Node Objects.
- JavaScript – DOM NodeList values() MethodThe NodeList values() method returns an iterator with the values from a NodeList, which is an array-like list of Node Objects.
- JavaScript – DOMTokenList add() MethodThe DOMTokenList add() method adds one or more tokens to a DOMTokenList, which is a set of space-separated tokens that can be accessed by index.
- JavaScript – DOMTokenList contains() MethodThe DOMTokenList contains() method returns “true” if a DOMTokenList contains a class. If not, it will return “false”.
- JavaScript – DOMTokenList entries() MethodThe DOMTokenList entries() method returns an iterator with the key/value pairs from a DOMTokenList.
- JavaScript – DOMTokenList forEach() MethodThe DOMTokenList forEach() method executes a callback function for each token in a DOMTokenList.
- JavaScript – DOMTokenList item() MethodThe DOMTokenList item() method returns the token at a specified index in a DOMTokenList.
- JavaScript – DOMTokenList keys() MethodThe DOMTokenList keys() method returns an iterator with the keys from a DOMTokenList.
- JavaScript – DOMTokenList length PropertyThe DOMTokenList length property returns the number of tokens in a DOMTokenList.
- JavaScript – DOMTokenList remove() MethodThe DOMTokenList remove() method removes tokens from the DOMTokenList, which is a set of space separated tokens that can be accessed by index.
- JavaScript – DOMTokenList replace() MethodThe DOMTokenList replace() method replaces a token in a DOMTokenList, which is a set of space separated tokens that can be accessed by index.
- JavaScript – DOMTokenList supports() MethodThe DOMTokenList supports() method returns “true” if a token in a DOMTokenList is one of the attribute’s supported tokens.
- JavaScript – DOMTokenList toggle() MethodThe DOMTokenList toggle() method toggles a token in a DOMTokenList on or off.
- JavaScript – DOMTokenList value PropertyThe DOMTokenList value property returns a DOMTokenList as a string
- JavaScript – DOMTokenList values() MethodThe DOMTokenList values() method returns an iterator with the keys from a DOMTokenList.
JavaScript Notes:
- When using JavaScript, single or double quotation marks are acceptable and work identically to one another; choose whichever you prefer, and stay consistent
- JavaScript is a case-sensitive language; firstName is NOT the same as firstname
- Arrays count starting from zero NOT one; so item 1 is position [0], item 2 is position [1], and item 3 is position [2] … and so on
- JavaScript variables must begin with a letter, $, or _
- JavaScript variables are case sensitive (x is not the same as X)
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.