Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM id property

HTML DOM id property

Element 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 ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the id property


Example

Example

Output the id of the link:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>

Runoob Tutorial(runoob.com)

title

head

<body>
<p>
<a id="myAnchor" href="//www.runoob.com">

Visit the Runoob Tutorial

a

p

<

script

var x=document.getElementById("myAnchor"); document.write(x.id);

script

body

html

Try it »


Element Object Reference Element object