1

i want to use a javascript variable screen as style backgroundattribute in a inline style declaration.

<div id ="content" style=" position: relative; top: -400px;  left: 0px;  width: 60px; height: 400px; z-index: 901;background-image: url(' + screen + ') "></div>
wetlip
  • 133
  • 3
  • 19
  • Read this - http://stackoverflow.com/questions/710275/how-to-add-update-an-attribute-to-an-html-element-using-javascript – klewis Mar 09 '13 at 19:11

1 Answers1

1
document.write('<div id ="content"
  style="
    position: relative;
    top: -400px;
    left: 0px;
    width: 60px;
    height: 400px;
    z-index: 901;
    background-image: url(' + screen + ')
  ">
</div>')

or

document.getElementById('content').style.backgroundImage = screen;
Cody Guldner
  • 2,888
  • 1
  • 25
  • 36
pawkow
  • 26
  • 2