Get the background image of a specific <div> element: - Javascript CSS Style Property

Javascript examples for CSS Style Property:backgroundImage

Description

Get the background image of a specific <div> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<h1>Hello World!</h1>

<div id="myDiv" style="background-image:url('http://java2s.com/resources/a.png');border:1px solid black;height:400px;width:400px;">This is a div element.</div>
<br>
<button type="button" onclick="myFunction()">Get the background image of div</button>

<script>
function myFunction() {/*from w  w w.  j a v  a  2 s  .c o  m*/
    console.log(document.getElementById("myDiv").style.backgroundImage);
}
</script>

</body>
</html>

Related Tutorials