How to use DOM Object GetElementById in JavaScript

In this article I am going to explain about DOM Object GetElementById() Method in JavaScript.
  • 1364

JavaScript DOM Object GetElementById() Method

JavaScript getElementById() method use for return the element that has id attribute with the specified value.

Syntax

document.getElementById("Id name")

Example 

<html>

<head>

    <script type="text/javascript">

 

        function myfun() {

            document.getElementById("cd").innerHTML = "Hello friends";

        };

 

    </script>

</head>

<body>

    <h5 id="cd">

        click the button for change this message</h5>

    <button onclick="myfun()">

        click me</button>

</body>

</html>

 

Output

 

Before Click button


getelemt1.gif

 

After click button

 

getelement2.gif


You may also want to read these related articles: here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2013 dotNetheaven. All rights reserved.