Development/JavaScript

document.getElementById("id")

연탄집게 2011. 6. 23. 17:47

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>