--- title: String.prototype.anchor() slug: Web/JavaScript/Reference/Global_Objects/String/anchor tags: - JavaScript - Method - Prototype - String translation_of: Web/JavaScript/Reference/Global_Objects/String/anchor original_slug: Web/JavaScript/Referencje/Obiekty/String/anchor ---
{{JSRef}}
Tworzy kotwicę HTML {{HTMLElement("a")}} do użycia jako cel odnośnika.
str.anchor(name)
nameUse the anchor() method to programmatically create and display an anchor in a document.
W składni łańcuch znaków reprezentuje literał tekstowy, który ma zobaczyć użytkownik. Łańcuch name reprezentuje atrybut name znacznika a.
Kotwice stworzone za pomocą metody anchor stają się elementami tablicy document.anchors.
anchor()Następujący przykład wewnątrz kodu HTML elementu script:
var myString = "Tabela zawartości";
document.body.innerHTML = myString.anchor("contents_anchor");
spowoduje otrzymanie na wyjściu kodu HTML:
<a name="contents_anchor">Tabela zawartości</a>