Search code examples
javascriptjquerycsssizewidth

How to set background size (height & width)?


I'm very new to JavaScript.

My code so far:

$("#Stage").css(
  "background-image",
  "url(BG.jpg)",
  "background-attachment", 
  "fixed"
);

What I want to do is have the background image at a set size so lets say: width: 100% and height: 100%.


Solution

  • You want to use background-size: 100%. Ensure that its browser support is compatible with your supported platforms.

    $("#Stage").css({ 
         "background-image": "url(BG.jpg)", 
         "background-attachment": "fixed",
         "background-size": "100%"
    });