본문 바로가기

Development/JavaScript

document.getElementById("id")

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



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>