Change Your Web Page with JavaScript Document Object Model Methods

By Andy Harris

Part of JavaScript & AJAX For Dummies Cheat Sheet

The Document Object Model methods shown in the following list offer you a great way to access and modify your Web pages through your JavaScript code.

  • myElement = document.getElementById(name);: Gets an element from the page with the specified ID and copies a reference to that element to the variable myElement.

  • myElement.innerHTML = value: Changes the value of the element to value.

  • document.onkeydown = keyListener: When a key is pressed, a function called keyListener is automatically activated.

  • document.onmousemove = mouseListener: When the mouse is moved, a function called mouseListener is automatically activated.

  • setInterval(function, ms);: Runs function each ms milliseconds.

  • myArray = document.getElementByName(name): Returns an array of objects with the current name (frequently used with radio buttons).