Reputation: 5575
I read here that I can position my div background image using:
var yValue = 20;
document.getElementById('a1').style.backgroundPosition = '0px ' + yValue + 'px';
But how would I do this for the body
background-position
using JavaScript, does the body take an id = 'bodyname'
for the getElementById()
function parameter?
<!DOCTYPE html>
<html>
<head>
<style>
body
{
background-image: url('image.gif');
background-repeat: repeat;
background-attachment:fixed;
background-position: 77px 100px;
}
</style>
</head>
<body>
</body>
</html>
Upvotes: 0
Views: 656
Reputation: 10728
You could give the body an id, there is no problem with that. But you could just as easily get the element by the tagname.
var bodyElements = document.getElementsByTagName('body');
As that method returns an array, the body tag would be the first element:
bodyElements[0]
Upvotes: 2
Reputation: 4808
In order to select your body with getElementById you need to add an id to it:
html:
<body id="bodyid"></body>
javascript:
var body = document.getElementById('bodyid');
Upvotes: 1