0

My Problem: I have two background images on the body tag one floating left and one right. The left image has a left padding of 50px and the right image has a right padding of 50px. I need to change the left padding for the left image and the right padding for the right image via javascript (not jquery).

Thanks for your help! :)

#body{
      background:url('http://www.w3schools.com/css/w3css.gif') no-repeat 50px 0px,
      url('http://www.w3schools.com/css/w3css.gif') no-repeat top right 50px;
}
Naftali
  • 144,921
  • 39
  • 244
  • 303

2 Answers2

1

Use this

document.getElementById('body').style.backgroundPosition = '150px 0, 100px 0';

The first 150px 0 is for the left image and 100px 0 is for the second image.

Here is a fiddle: http://jsfiddle.net/enve/9a32b/

Idrizi.A
  • 9,819
  • 11
  • 47
  • 88
0

Give the tag an id like id="body" then,

document.getElementById("body").style["padding-left"] = "50px"; document.getElementById("body").style["padding-right"] = "50px";

see this stackoverflow question

Community
  • 1
  • 1
Nikola
  • 817
  • 13
  • 19