X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Document getElementById() Method

Document Object Reference Document Object

Definition and Usage

The getElementById() method accesses the first element with the specified id.

Syntax

document.getElementById("id")

Parameter Description
id Required. The id of the element you want to access/manipulate


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The getElementById() method is supported in all major browsers.


Example

Example

Alert innerHTML of an element with a specific ID:

<html>
<head>
<script>
function getValue()
  {
  var x=document.getElementById("myHeader");
  alert(x.innerHTML);
  }
</script>
</head>
<body>

<h1 id="myHeader" onclick="getValue()">Click me!</h1>

</body>
</html>

Try it yourself »


Document Object Reference Document Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook