Anchor id Property

Anchor Object Reference Anchor Object

Example

Get the id of a link:

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

The result of x will be:

myAnchor

Try it yourself »

Definition and Usage

The id property sets or returns the value of the id attribute of a link.

The id attribute specifies the id of an anchor, and can be used to create a bookmark inside a document.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The id property is supported in all major browsers.


Syntax

Return the id property:

anchorObject.id

Set the id property:

anchorObject.id=id

Property Values

Value Description
id Specifies the id of a link

Technical Details

Return Value: A String, representing the id of the link

More Examples

Example

Change the id of a link:

document.getElementById("myAnchor").id = "newid";

Try it yourself »

Example

A demonstration of how to change the id of an anchor to create a bookmark inside a document:

document.getElementById("typo").id = "C6";

Try it yourself »

Related Pages

HTML reference: HTML id attribute


Anchor Object Reference Anchor Object

SHARE THIS PAGE

Color Picker

colorpicker