Javascript DOM HTML Body get background image

Introduction

Return the background image of a document:

alert(document.body.style.backgroundImage);

View in separate window

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

<h1>Hello World!</h1>
<button type="button" onclick="myFunction()">Get background image</button>
<p id="demo"></p>
<script>
function myFunction() {//from   www .j ava  2  s .  c  om
  document.getElementById("demo").innerHTML =document.body.style.backgroundImage;
}
</script>

</body>
</html>



PreviousNext

Related