JavaScript > HTML DOM

DOM Document in JavaScript

What is DOM Document and what is the use od DOM Document in javascript?


HTML DOM Document

  1. HTML DOM Document is defined as an object in the webpage.
  2. HTML DOM Document is used to represent webpage.
  3. HTML DOM Document is used to access any HTML element.

Some of HTML DOM Document which are used to access HTML.

Finding HTML Elements

  • document.getElementById(id) - Finds an element using element id
  • document.getElementByTagName(name) - Finds element by tag name
  • document.getElementByClassName(name) - Finds element by class name.

Changing HTML ELements

  • element.innerHTML= new html content  - changes the innerHTML of element
  • element.attribute= new value - changes the attribute value of HTMLelement
  • element.setAttribute(attribute, value)-changes the attribute value of HTMLelement
  • element.style.property=new style-changes the style of an HTML element

Adding and Deleting elements

  • document.createElement(element)- creates an HTML element
  • document.removeChild(element)-removes an HTML element
  • document.replaceChild(element)-replaces an HTML element
  • document.appendchild(element)- adds an HTML element.
  • document.write(text)- Write in to HTML output stream.

Adding Event handlers

  • document.getElementById(id).onclick=function(){code} - Adds event handler code to onclick event.

Finding HTML Objects

  • document.anchors- returns all <a> elements which have name attribute
  • document.URL - returns url of the document.
  • document.body - returns body of the element
  • document.baseURI - returns absolute base URI of the document.
  • document.cookie - returns the document cookies
  • document.doctype - returns document doctype.
  • document.documentElement- returns HTML element.
  • document.documentMode - returns the mode used by the user.
  • document.documentURI - returns the document of the URI.
  • document.domain -  returns the domain name of the server.
  • document.embeds - It returns all <embed> elements.
  • document.forms - returns all <form> elements.
  • document.head - returns all <head> element.
  • document.images - returns all <img> elements.
  • document.implementation - returns all DOM implementations.
  • document.inputEncoding - returns all documents encoding.
  • document.lastModified - returns date and time of the document.
  • document.links - defines all <href> attributes.
  • document.readyState - returns current status of the document.
  • document.URI refferer - returns URI of the refferer.
  • document.scripts - returns all <script> elements.
  • document.title - returns all<title> element
  • document.StrictErrorChecking - returns if error checking is enforced.
 Views: 280 | Post Order: 205



Write for us