Get Body Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Body

Introduction

The Body object represents an HTML <body> element.

You can access a <body> element by using getElementsByTagName():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">set the background color of the document</button>

<p id="demo"></p>

<script>
function myFunction() {//from w  w w.j  av  a 2s . co m
    var x = document.getElementsByTagName("BODY")[0];
    x.style.backgroundColor = "#EEE";
}
</script>

</body>
</html>

Related Tutorials