DOM Properties & Methods Flashcards
document.activeElement
DOM property that returns the element that has focus (read only)
const focus = document.activeElement .tagName;
.baseURI
Property that returns the base URI of the document (read only)
let base = document.baseURI;
.body
The body property sets or returns the body element.
const docBody = document.body.innerHTML; //returns all the HTML content
document. body.style… //changes CSS
document. body.innerHTML = “whole new HTML content”;
.cookie
Property that sets or returns a semi-colon-separated list of key value pairs
let cookieList = document.cookie;
document.cookie = “name=joe; surname=smith”;
.documentURI
sets or returns a documents location
returns null if document was created in memory
.domain
returns the domain name of the server
returns null if the document is created in memory
.embeds
returns a collection of all ‘embed’ elements in the document (read only)
.forms
returns a collection of all ‘form’ elements in the document (read only)
let formCount = document.forms.length;
let id = document.forms[0].id;
.head
returns the head element of the document
document.images
returns a collection of all ‘img’ elements in the document
document.links
returns a collection of all ‘a’ and ‘area’ elements with href attributes
document.URL
returns the full document URL
What is an HTML collection? What are the three properties?
An HTMLCollection is a list of HTML elements.
The elements in a collection can be accessed by index (starts at 0).
.length; returns the number of elements
.item(); returns the element at a specified index
.namedItem(); returns the element with a specific id
What are the differences between HTMLcollection and NodeList?
What methods create each?
HTMLcollection is live, if an element is added to the DOM, the list will also change. [getElementsByClassName(), getElementsByTagName()]
NodeList is a static collection, the list will not change if an element is added to the DOM. [querySelectorAll(), childNodes, getElementsByName()]
What is a NodeList, what are its six properties?
A NodeList is a static collection (list) of Node Objects.
The nodes in a NodeList can be accessed by index (starts at 0).
.length; returns the number of nodes
.entries(); returns an iterator with key:value pairs
.forEach(); executes a callback function for each node
.item(); returns the node at the specified index
keys(); returns an iterator with the keys from the list
.values() returns an iterator with the values from the list