One way that I am trying to change the background of a div is by using a function. Below is an example of the html code I am working with:
$scope.Background = 'img/seg5en.png';
document.getElementById("Bstyle").style.background = "url("+$scope.Background+") no-repeat center fixed;";
console.log(document.getElementById("Bstyle").style.background);
console.log("url("+$scope.Background+") no-repeat center fixed;");
Initially, the variable $scope.Background
points to "img/bg.png
" which was defined at the beginning of my document. The first console.log statement shows that the style.background value is "img/bg.png
".
Strangely, the second console.log
output displays:
url(img/seg5en.png) no-repeat center fixed
.
I am puzzled as to why my html page does not reflect this change in background image.