We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

String.anchor Redirect 1


The anchor() method creates an <a> HTML anchor element that is used as a hypertext target.




A string respresenting the name attribute of the a tag to be created.


Use the anchor method to programmatically create and display an anchor in a document.

In the syntax, the text string represents the literal text that you want the user to see. The name parameter string represents the name attribute of the <a> element.

Anchors created with the anchor method become elements in the document.anchors array.


Example: Using anchor

var myString = "Table of Contents";

document.body.innerHTML = myString.anchor("contents_anchor");

will output the following HTML:

<a name="contents_anchor">Table of Contents</a>


Specification Status Comment
ECMAScript Language Specification 6th Edition (ECMA-262) Draft Initial definition. Implemented in JavaScript 1.0.
Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) 1.0 (1.7 or earlier) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) 1.0 (1.0) (Yes) (Yes) (Yes)

Gecko-specific notes

Starting with Gecko 17 the " (quotation mark) is replaced by its HTML reference character &quot; in strings supplied for the name parameter.

See also

Document Tags and Contributors

Last updated by: Sheppy,