More DOM Methods and Properties

The following sections are a summary of some DOM classes, methods, and properties. A more complete list can be found in the reference links below. You do NOT need to memorize everything on these reference pages. We are providing them to you as a guide for your future studies of the DOM.

  1. W3Schools DOM reference .
  2. MDN DOM reference .


The global variable window is an instance of the Window class. The Window class represents the browser window. In the case of multi-tabbed browsers, the global window variable represents the specific tab in which the JavaScript code is running.

Method or PropertySyntaxDescription
alertwindow.alert("String message")Displays a dialog box with a message and an “ok” button to close the box.
confirmwindow.confirm("String message")Displays a dialog box with a message and returns true if the user clicks “ok” and false if the user clicks “cancel”.
locationwindow.locationObject that represents and alters the web address of the window or tab.
consolewindow.consoleRepresents the debugging console. Most common and basic use is window.console.log().

When using JavaScript in the browser environment, methods and properties defined on the Window class are exposed as global functions and variables. An example of this is window.console.log() is accessible by referencing console.log() directly.


The global document variable is an instance of the Document class. The Document class represents the HTML web page that is read and displayed by the browser. The Document class provides properties and methods to find, add, remove, and alter HTML elements inside on the web page.

Method or PropertySyntaxDescription
titledocument.titleRead or set the title of the document.
getElementByIddocument.getElementById("example-id")Returns a reference to the element whose id attribute matches the given string value.
querySelectordocument.querySelector("css selector")Returns the first element that matches the given CSS selector.
querySelectorAlldocument.querySelectorAll("css selector")Returns a list of elements that match the given CSS selector.

querySelector and querySelectorAll use the CSS selector pattern to find matching elements. The pattern passed in must be a valid CSS selector. Elements will be found and returned the same way that elements are selected to have CSS rules applied.


HTML documents are made up of a tree of elements. The Element class represents an HTML element.

Method or PropertySyntaxDescription
getAttributeelement.getAttribute("id")Returns the value of the attribute.
setAttributeelement.setAttribute("id", "string-value")Sets the attribute to the given value. that allows reading and setting INLINE CSS properties.
innerHTMLelement.innerHTMLReads or sets the HTML inside an element.

Check Your Understanding


What value will response have if the user clicks Cancel?

let response = window.confirm("String message");

Which of these are TRUE about selecting DOM elements?

  1. You can select elements by CSS class name
  2. You can select elements by id attribute value
  3. You can select elements by tag name
  4. All of the above