HTML DOM anchorsSammlung
Dokumentobjekt
Definition und Verwendung
Die anchors-Sammlung gibt ein Array aller Hyperlinks auf der aktuellen Seite zurück.
Syntax
document.anchors[].Eigenschaft
Browser-Unterstützung
![]()
![]()
![]()
![]()
![]()
Alle wichtigen Browser unterstützen die anchors-Sammlung.
Beispiele
Beispiel 1
Gibt die Anzahl der Links im Dokument zurück:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Beispiel (example.com)</title>
</head>
<body>
<a name="html">HTML-Tutorial</a><br>
<a name="css">CSS-Tutorial</a><br>
<a name="xml">XML-Tutorial</a><br>
<a href="../js/index.html">JavaScript-Tutorial</a>
<p>Anzahl der Anker:
<script>
document.write(document.anchors.length);
</script></p>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Beispiel (example.com)</title>
</head>
<body>
<a name="html">HTML-Tutorial</a><br>
<a name="css">CSS-Tutorial</a><br>
<a name="xml">XML-Tutorial</a><br>
<a href="../js/index.html">JavaScript-Tutorial</a>
<p>Anzahl der Anker:
<script>
document.write(document.anchors.length);
</script></p>
</body>
</html>
Die Ausgabe des obigen Beispiels:
Anzahl der Anker: 3
Selbst ausprobieren »
Beispiel 2
Gibt den Ankertext des ersten Hyperlinks im Dokument zurück:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Beispiel (example.com)</title>
</head>
<body>
<a name="html">HTML-Tutorial</a><br>
<a name="css">CSS-Tutorial</a><br>
<a name="xml">XML-Tutorial</a>
<p>Der erste Anker im Dokument:
<script>
document.write(document.anchors[0].innerHTML);
</script>
</p>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Beispiel (example.com)</title>
</head>
<body>
<a name="html">HTML-Tutorial</a><br>
<a name="css">CSS-Tutorial</a><br>
<a name="xml">XML-Tutorial</a>
<p>Der erste Anker im Dokument:
<script>
document.write(document.anchors[0].innerHTML);
</script>
</p>
</body>
</html>
Die Ausgabe des obigen Beispiels:
Der erste Anker im Dokument: HTML Tutorial
Selbst ausprobieren »
Dokumentobjekt Andere Erweiterungen