Javascript DOM HTML Body get background

Introduction

Return the background property values of a document:

document.body.style.background;

View in separate window

<!DOCTYPE html>
<html>
<body style="background:#f3f3f3 url('background1.png') no-repeat right top;">

<h1>Hello World!</h1>

<button type="button" onclick="myFunction()">Get background values</button>

<p id="demo"></p>
<script>
function myFunction() {/*  w w w . ja  va 2  s. c  om*/
  document.getElementById("demo").innerHTML = document.body.style.background;
}
</script>

</body>
</html>



PreviousNext

Related