JavaScript DOM Document Object Model

The DOM is W3C (World Wide Web Consortium) standard. It is a standard for accessing the documents. The Document Object Model is concerned with the whole html document's elements.

When an html document get loaded in the browser, a document object is created which can be used to add dynamic content to the webpage and to access different elements of the page. The object model defines all the html elements as objects, and also defines the various properties, methods, and events for all the HTML elements.

Properties of document object

Methods of document object

Property Description
write("sometext") It displays the specified text on the doucment.
writeln("sometext") It displays the text with newline character at the end.
getElementByID() It returns the element having the given id.
getElementByName() It returns the elements having the specified name.
getElementsByTagName() It returns the elements having the specified tag name.
getElementByClassName() It Returns all the elements having the specified class name.

Accessing field value by document object

In this example, we are going to input text by user and using to get the value of name field.

In this example document is the root element that represents the html document.form1 is the name of the form.
name is the attribute name of the form input text, and value is the property, that returns the value of the input text.

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title> JavaScript Document Object Model (DOM) </title>
function printvalue(){
alert("Welcome: "+name);
<form name="form1">
Enter Name : <input type="text" name="name"/>
<input type="button" onclick="printvalue()" value="Print name"/>


JavaScript Document Object Model (DOM)
Enter Name :

Color Picker

List of color names supported by all browser »

Character Code

List of character codes to display special character »

Language Code

List of all language supported by all browser »

Country Code

List of Country code supported by all browser »

Latest Updates

PHP Introduction

How to Run a PHP program in Xampp?

How can I create a phpinfo.php page?

How to Define a Variable in PHP

PHP Echo and Print Statements

Working with PHP Operators

Understanding the PHP Data Types

How to Write Comments in PHP

How to Define a Constant in PHP

PHP if...else...elseif Statements