Add background image with Javascript - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image


Add background image with Javascript

Demo Code

ResultView the demo in separate window

      <title>Dynamic Bg image</title> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from  w ww  . j a  v a2s . c  o m*/
 var cards = "";
 var posX = 200;
 var posY = 500;
document.getElementById("cardImg").style.background = "url(" + cards + ") "+posX+"px "+ posY+"px";

      <div id="cardImg" style="width:100px;height:100px;"> 

Related Tutorials