HTML Dom Tutorial

HTML Dom Tutorial thumbnail
DHTML is when JavaScript is used to alter elements within the HTML DOM.

HTML DOM is an acronym that means HyperText Markup Language Document Object Model. This describes the hierarchy of the HTML Document object and all of the objects and methods within it. Using this concept within a scripting language, such as JavaScript, creates Dynamic HTML, or DHTML. DHTML is when JavaScript is used to alter elements within the HTML DOM.

Instructions

    • 1

      Write some HTML with an element identified by its id attribute for DOM access later.

      <html>

      <head>

      <title>HTML DOM Tutorial</title>

      </head>

      <body>

      <div id="myDiv">contents of div</div>

      outside of div

      </body>

      </html>

      You will use the HTML DOM to access the <div> element we just created.

    • 2

      Insert JavaScript into the <head> element of your HTML document. This one will point the variable "myElement" to the first HTML element with the "id" attribute set to "myDiv," and should work in almost every web browser.

      <script type="text/javascript">

      myElement = document.getElementById("myDiv");

      </script>

      To retrieve an array of HTML elements, you could instead use the less supported methods getElementsByTagName or getElementsByClassName. Refer to the Resources section for further reading on these methods.

    • 3

      Manipulate attributes of the HTML element to make DHTML.

      myElement.innerHTML = "new contents of div";

      myElement.style.backgroundColor = "red";

      These two lines of JavaScript will change the contents of myDiv to the new text, and then change the background color of myDiv to red.

Tips & Warnings

  • These are the steps for implementing the HTML DOM in JavaScript. For a full reference of HTML DOM objects and methods, use the links in the References and Resources sections.

Related Searches:

References

Resources

  • Photo Credit Nick Koudis/Photodisc/Getty Images

Comments

You May Also Like

  • Javascript DOM Tutorial

    Understanding the DOM is key to using JavaScript effectively. The elements of a web page that are available to JavaScript functions exist...

  • HTML 5 Tutorial

    HTML 5 is the newest iteration of HTML, the basic language of the Web. When finalized, it will replace both current versions,...

  • Dreamweaver MX PDF Tutorial

    Dreamweaver doesn't have a built-in PDF creation tool, but the Web pages you make with the program can be easily converted into...

  • HTML 4.01 Tutorial

    HTML 4.01 is a specification for the HyperText Markup Language, the basic language used to create web pages. Introduced in 1999 as...

  • How to Link to a Word Document With an Unbound Object Frame

    Connecting the word processing power of a Word Document with the capabilities of an Access database can save time and effort. While...

  • HTML Object Tutorial

    The "object" element was originally developed to be a generic way to insert any type of media object, even images. Inconsistent levels...

  • Adding Javascript Dynamically With DOM Scripting

    The Document Object Model, or DOM, is a representation of a website stored in the memory of a computer. JavaScript is used...

  • How to Change DOM Property Values

    The Document Object Model (DOM) is the representation of the objects that make up a web page. Web developers alter the property...

  • How to Set the Width of a DIV

    DIV means division in HTML. Using DIV tags allows you to style an element differently than other elements in a page. For...

  • How to Convert MIDI to Audio: GarageBand Tutorial

    Learn how to convert MIDI to audio using Apple's Garageband music recording software in this free online video tutorial.

  • How to Write an APA Style Paper

    Writing a college paper in APA style only seems like a hassle. Being proficient with it will help you beyond any classroom....

  • How to Retrieve Images From an HTML File in PHP

    Web pages can contain many kinds of media, and sometimes you want your PHP application to be able to analyze and extract...

  • Advanced Flash Game Tutorial

    All computer games incorporate mathematics even though the end-user rarely knows it. Math functions are used to track user input, keep score,...

  • How to Detect Buttons With JavaScript

    JavaScript can interact with the HTML elements on a webpage by using a concept known as the HTML Document Object Model, or...

  • HTML Javascript Tutorial

    HyperText Markup Language (HTML) is the markup language used to build a Web page, while JavaScript is a scripting language that builds...

  • HTML Check Box Tutorial

    Check boxes can be an important component of HTML forms. They allow a user the opportunity to select multiple choices related to...

  • How to Set CSS Styles With JavaScript

    Setting CSS styles with JavaScript is a straightforward and effective way to make a web page more dynamic and stimulating for visitors....

  • How to Remove DIV in Javascript

    Using JavaScript code you can manipulate HTML Web page elements. A JavaScript function can be designed to remove an HTML element such...

Related Ads

Featured