Site icon i2tutorials

Javascript DOM- methods

Javascript DOM- methods

 

The important methods of document object:

 

Method                                              Description

write(“string”)                         writes the given string on the document.

writeln(“string”)                      writes the given string on the document with a newline character at the end.

getElementById()                    returns all element having the given id value.

getElementsByName()            returns the elements having the given name value.

getElementsByTagName()      returns the elements having the given tag name.

getElementsByClassName()   returns the elements having the given class name.

 

 

Example:

 

<!DOCTYPE html>
<html>
<body>
<h2>My First Page</h2>
<p id="i2t"></p>
<script>
document.getElementById("i2t").innerHTML = "Welcome to I2tutorials";
</script>
</body>
</html>

 

OUTPUT:

 

My First Page
Welcome to I2tutorials

 

In the example above,

  1. getElementById is a method.
  2. innerHTML is a property.

 

In the example above,

            getElementById method used id=”demo” to find the element.

 

 

 

 

Exit mobile version