diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:42:52 -0500 |
commit | 074785cea106179cb3305637055ab0a009ca74f2 (patch) | |
tree | e6ae371cccd642aa2b67f39752a2cdf1fd4eb040 /files/pt-br/web/api/document/anchors | |
parent | da78a9e329e272dedb2400b79a3bdeebff387d47 (diff) | |
download | translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.gz translated-content-074785cea106179cb3305637055ab0a009ca74f2.tar.bz2 translated-content-074785cea106179cb3305637055ab0a009ca74f2.zip |
initial commit
Diffstat (limited to 'files/pt-br/web/api/document/anchors')
-rw-r--r-- | files/pt-br/web/api/document/anchors/index.html | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/files/pt-br/web/api/document/anchors/index.html b/files/pt-br/web/api/document/anchors/index.html new file mode 100644 index 0000000000..624c955b0e --- /dev/null +++ b/files/pt-br/web/api/document/anchors/index.html @@ -0,0 +1,107 @@ +--- +title: Document.anchors +slug: Web/API/Document/anchors +tags: + - API + - Deprecated + - HTML DOM + - NeedsCompatTable + - Property + - Reference +translation_of: Web/API/Document/anchors +--- +<div>{{APIRef("DOM")}}</div> + +<p>{{deprecated_header("HTML5")}}</p> + +<p><code>anchors</code> retorna uma lista de todas as âncoras no documento.</p> + +<h2 id="Syntax" name="Syntax">Sintaxe</h2> + +<pre class="syntaxbox"><var>nodeList</var> = document.anchors; +</pre> + +<h2 id="Example" name="Example">Exemplo</h2> + +<pre class="brush:js">if ( document.anchors.length >= 5 ) { + dump("dump found too many anchors"); + window.location = "http://www.google.com"; +} +</pre> + +<p>O código a seguir é um exemplo que popula automaticamente um índice de conteúdo com cada âncora encontrada na página:</p> + +<pre class="brush:html"><!DOCTYPE html> +<html lang="en"> +<head> +<meta charset="UTF-8" /> +<title>Test</title> +<script> +function init() { + var toc = document.getElementById("toc"); + var i, li, newAnchor; + for (i = 0; i < document.anchors.length; i++) { + li = document.createElement("li"); + newAnchor = document.createElement('a'); + newAnchor.href = "#" + document.anchors[i].name; + newAnchor.innerHTML = document.anchors[i].text; + li.appendChild(newAnchor); + toc.appendChild(li); + } +} +</script> + +</head> +<body onload="init()"> + +<h1>Title</h1> +<h2><a name="contents">Contents</a></h2> +<ul id="toc"></ul> + +<h2><a name="plants">Plants</a></h2> +<ol> + <li>Apples</li> + <li>Oranges</li> + <li>Pears</li> +</ol> + +<h2><a name="veggies">Veggies</a></h2> +<ol> + <li>Carrots</li> + <li>Celery</li> + <li>Beats</li> +</ol> + +</body> +</html> +</pre> + +<p><a href="https://jsfiddle.net/S4yNp">View on JSFiddle</a></p> + +<h2 id="Notes" name="Notes">Notas</h2> + +<p>Por motivos de compatibilidade, o conjunto de âncoras retornadas por <code>anchors</code> contém apenas as âncoras criadas com o atributo <code>name</code>, não incluindo as âncoras criadas com o atributo {{ htmlattrxref("id") }}.</p> + +<h2 id="Specifications" name="Specifications">Especificações</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-document-anchors', 'Document.anchors')}}</td> + <td>{{ Spec2('HTML WHATWG') }}</td> + <td>Obsoleted.</td> + </tr> + <tr> + <td>{{SpecName('DOM2 HTML', 'html.html#ID-7577272', 'Document.anchors')}}</td> + <td>{{ Spec2('DOM2 Events') }}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> |