W3Schools.com

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 type="text/javascript">
var x=document.getElementById("myAnchor");
document.write(x.id);
</script>

</body>
</html>

Try it yourself »


HTMLElement Object Reference HTMLElement Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE