aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/api/document/body/index.html
blob: cb21522c4f6deb9de8474ccdd562ae7419b40003 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
title: Document.body
slug: Web/API/Document/body
translation_of: Web/API/Document/body
---
<div>{{APIRef("DOM")}}</div>

<p>Retorna o elemento {{HTMLElement("body")}} ou o {{HTMLElement("frameset")}} do documento atual, ou <code>null</code> se nenhum destes elementos existir.</p>

<h2 id="Syntax" name="Syntax">Sintaxe</h2>

<pre class="syntaxbox"><em>var objRef</em> = document.body;
document.body = <em>objRef;</em></pre>

<h2 id="Example" name="Example">Exemplo</h2>

<pre class="brush:js">// No HTML: &lt;body id="oldBodyElement"&gt;&lt;/body&gt;
alert(document.body.id); // "oldBodyElement"

var aNewBodyElement = document.createElement("body");

aNewBodyElement.id = "newBodyElement";
document.body = aNewBodyElement;
alert(document.body.id); // "newBodyElement"
</pre>

<h2 id="Notes" name="Notes">Notas</h2>

<p><code>document.body</code> é o elemento que envolve o conteúdo do documento. Em documentos com conteúdo no <code>&lt;body&gt;</code>, retorna o elemento <code>&lt;body&gt;</code>, e em documentos que usam frameset, retorna o elemento <code>&lt;frameset&gt;</code> mais periférico.</p>

<p>Apesar do <code>body</code> ser configurável, definir um novo <code>body</code> em um documento irá remover todos os elementos contidos no elemento <code>&lt;body&gt;</code> existente.</p>

<h2 id="Specification" name="Specification">Especificação</h2>

<ul>
 <li><a class="external" href="http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-56360201">DOM Level 2 HTML: HTMLDocument.body</a></li>
 <li><a class="external" href="http://www.w3.org/TR/html5/dom.html#dom-tree-accessors" title="http://www.w3.org/TR/html5/dom.html#dom-document-head">HTML5: DOM Tree Accessors</a></li>
</ul>

<h2 id="Veja_Também">Veja Também</h2>

<ul>
 <li>{{domxref("document.head")}}</li>
</ul>