Search w3schools.com:

SHARE THIS PAGE

HTMLElement id Property

HTMLElement Object Reference HTMLElement Object

Definition and Usage

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

Syntax

HTMLElementObject.id=id


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The id property is supported in all major browsers.


Example

Example

Output the id of a link:

<html>
<body>

<p><a id="myAnchor"
href="http://www.w3schools.com">Visit W3Schools.com</a></p>

<script>
var x=document.getElementById("myAnchor");
document.write(x.id);
</script>

</body>
</html>

Try it yourself »


HTMLElement Object Reference HTMLElement Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]