HTML DOM idProperty

元素对象参考手册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>Example Tutorial (example.com)</title> </head> <body> <p><a id="myAnchor" href="//www.example.com">Visit Example</a></p> <script> var x=document.getElementById("myAnchor"); document.write(x.id); </script> </body> </html>

Try it »


元素对象参考手册Element Object

Other Extensions