String.prototype.anchor()

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. 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.

O método anchor() cria uma string começando com uma tag inicial <a name="...">, um texto e uma tag final </a>.

Aviso: Não use este método. Ao invés, use DOM APIs. Além disso, a especificação HTML não permite mais que o elemento <a> tenha um atributo "name", portanto, esse método nem mesmo cria uma tag válida.

Sintaxe

str.anchor(name)

Parâmetros

name

Uma string que deve representar o valor do atributo name.

Valor retornado

Uma string começando com uma tag de início <a name="name">, depois o valor da string e, em seguida, uma tag de fim </a>.

Descrição

Não use este método. Ao invés, use DOM APIs. Além disso, a especificação HTML não permite mais que o elemento <a> tenha um atributo "name", portanto, esse método nem mesmo cria uma tag válida.

Exemplos

Usando anchor()

js
const nome = 'Ricardo';
console.log(nome.anchor('https://developer.mozilla.org/pt-BR/)');

irá retornar o seguinte código HTML:

html
'<a name="https://developer.mozilla.org/pt-BR/">Ricardo</a>'

Especificações

Specification
ECMAScript Language Specification
# sec-string.prototype.anchor

Compatibilidade com navegadores

BCD tables only load in the browser

Veja também