W3Schools.com

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 type="text/javascript">
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
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE