Our volunteers haven't translated this article into বাংলা (বাংলাদেশ) yet. Join us and help get the job done!
You can also read the article in English (US).

Returns the <body> or <frameset> node of the current document, or null if no such element exists.

Syntax

var objRef = document.body; 
document.body = objRef;

Example

// in HTML: <body id="oldBodyElement"></body>
alert(document.body.id); // "oldBodyElement"

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

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

Notes

document.body is the element that contains the content for the document. In documents with <body> contents, returns the <body> element, and in frameset documents, this returns the outermost <frameset> element.

Though body is settable, setting a new body on a document will effectively remove all the current children of the existing <body> element.

Specification

Specification Status Comment
HTML Living Standard
The definition of 'Document.body' in that specification.
Living Standard  
HTML 5.1
The definition of 'Document.body' in that specification.
Recommendation  
HTML5
The definition of 'Document.body' in that specification.
Recommendation  
Document Object Model (DOM) Level 2 HTML Specification
The definition of 'Document.body' in that specification.
Obsolete  
Document Object Model (DOM) Level 1 Specification
The definition of 'Document.body' in that specification.
Obsolete Initial definition.

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support1 Yes2169.64
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes Yes Yes Yes1 Yes5 ?

1. The body property was implemented on the HTMLDocument interface in Firefox for a long time, hence document.body would not return the <body> element if the document's Content-Type was not set to text/html or application/xhtml+xml (or if it came from DOMParser.parseFromString without the text/html type being used). This has been fixed in Firefox 60.

 

See Also

ডকুমেন্ট ট্যাগ এবং অবদানকারী

সর্বশেষ হালনাগাদ করেছেন: fscholz,