DOM Manipulation2/17

Document Properties

Document Properties

The document object has many useful properties!

Common Properties

PropertyWhat It Returns
document.titlePage title (string)
document.URLCurrent URL (string)
document.domainDomain name
document.bodyThe <body> element
document.headThe <head> element
document.formsAll <form> elements
document.imagesAll <img> elements
document.linksAll <a> elements

Examples

// Get page title
console.log(document.title);

// Check URL
console.log(document.URL);

// Count images on page
console.log(document.images.length);

// Check if on localhost
const isLocal = document.URL.includes("localhost");

String Methods Work!

Since many properties return strings, you can use string methods:

// Check domain
document.URL.includes("github");  // true/false

// Get title length
document.title.length;

// Uppercase title
document.title.toUpperCase();

Your Turn!

Check if the document URL contains "localhost" and store the result in isLocal.