Computer >> Computer tutorials >  >> Programming >> Javascript

How to work with document.body in JavaScript?


Use the document.body property in JavaScript to get the body of the document i.e. <body> tag.

Example

You can try to run the following code to implement document.body property in JavaScript.

<!DOCTYPE html>
<html>
   <head>
      <title>JavaScript Example</title>
   </head>
   <body>
      <p>Demo Text</p>
      <script>
         document.body.style.backgroundColor = "blue";
      </script>
   </body>
</html>