X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM id Property

HTMLElement Object Reference Element 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 Element Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook