Переклад не закінчено. Будь ласка, допоможіть перекласти цю статтю з англійської.

Deprecated
This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Avoid using it and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

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

Syntax

str.anchor(name)

Parameters

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

Return value

A string containing an <a> HTML element.

Description

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.

Examples

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>

Specifications

Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'String.prototype.anchor' in that specification.
Standard Initial definition. Implemented in JavaScript 1.0. Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers.

Polyfill

if (!String.prototype.anchor)
    String.prototype.anchor = function(x){
        return '<a name="' + x + '">' + this + '</a>'
    }

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung InternetNode.js
Basic support
Deprecated
Chrome Full support YesEdge Full support YesFirefox Full support 1
Notes
Full support 1
Notes
Notes Starting with version 17, the quotation mark (") is replaced by its HTML reference character (") in strings supplied for the name parameter.
IE No support NoOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes

Legend

Full support  
Full support
No support  
No support
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.

See also

Мітки документа й учасники

Зробили внесок у цю сторінку: RomanGorbatko
Востаннє оновлена: RomanGorbatko,