javascript image source and background image

The goal is to set an image source and the background image of a div using javascript

by Ariel Balter

HTML

<div id="divtest">Hello</div>
<img id="imgtest" />
<img id="imgreal" src="http://www.premiumbeat.com/blog/wp-content/uploads/2012/12/free.jpeg" />

CSS

#divtest {
    border: 3px solid black;
    height: 200px;
    width: 200px;
}
img {
    height: 200px;
    width: 200px;
}
#imgtest {
    border: 3px solid red;
}
#imgreal {
    border: 3px solid green;
}

JavaScript

var string = "url('http://www.premiumbeat.com/blog/wp-content/uploads/2012/12/free.jpeg')";
alert(string)
document.getElementByID("divtest").style.backgroundImage = string;
document.getElementByID("imgtest").src = string;