HTML DOM idProperty
Definition and Usage
The id property sets or returns the id of an element.
Syntax
HTMLElementObject.id=id
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the id property
Example
Example
Output the id of the link:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial (example.com)</title>
</head>
<body>
<p><a id="myAnchor" href="//www.example.com">Visit Example</a></p>
<script>
var x=document.getElementById("myAnchor");
document.write(x.id);
</script>
</body>
</html>
Try it »
Other Extensions
Element Object