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.
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()
const nome = 'Ricardo';
console.log(nome.anchor('https://developer.mozilla.org/pt-BR/)');
irá retornar o seguinte código HTML:
'<a name="https://developer.mozilla.org/pt-BR/">Ricardo</a>'
Especificações
Specification |
---|
ECMAScript® 2025 Language Specification # sec-string.prototype.anchor |
Compatibilidade com navegadores
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
anchor |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Deprecated. Not for use in new websites.
- See implementation notes.