Easy Tutorial
❮ Prop Style Borderimagesource Prop Datetime Value ❯

HTML DOM id Attribute

Element Object


Definition and Usage

The id attribute sets or returns the id of an element.

Syntax


Browser Support

All major browsers support the id attribute.


Example

Output the id of a link:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>tutorialpro.org(tutorialpro.org)</title>
</head>
<body>

<p><a id="myAnchor" href="//www.tutorialpro.org">Visit tutorialpro.org</a></p>
<script>
var x = document.getElementById("myAnchor");
document.write(x.id);
</script>

</body>
</html>

Element Object

❮ Prop Style Borderimagesource Prop Datetime Value ❯