set attribute javascript background image
document.body.style.backgroundImage = "url('img_tree.png')";function bg() {
var imgCount = 3;
var dir = 'http://local.statamic.com/_themes/img/';
// I changed your random generator
//floor: helps getting a random integer
var randomCount = (Math.floor(Math.random() * imgCount));
// I changed your array to the literal notation. The literal notation is preferred.
var images = ['001.png', '002.png', '003.png'];
// I changed this section to just define the style attribute the best way I know how.
document.getElementById('banner').setAttribute("style", "background-image: url(" + dir + images[randomCount] + ");background-repeat: no-repeat;background-size: 388px 388px");
}
// Don't forget to run the function instead of just defining it.
bg();
Also in JavaScript:
- see if array contains array javascript
- turn Iterator into array JS
- javascript create object empty
- settimeout in loop javascript
- postfix date javascript
- jest tranform image
- ./src/index.js Line 0: Parsing error: Cannot find module '@babel/helper-validator-identifier'
- js opposite of preventdefault
- js delete all array items
- use two div id in jquery
- javascript random six digit number with animation
- javascript how to trigger and event
- javascript ajax show result type min 3 characters
- javascript add text to textarea overwrite
- find unique elements in array javascript
- error: Error: Unable to resolve module `crypto` from `node_modules\crypto-js\core.js`: crypto could not be found within the project.
- chart.js line chart multiple labels
- get child of child javascript
- getstaticpaths with redux
- biden trump javascript real time election
- factorial in javascript using for loop
- ajax calls
- javascript rpg tutorial
- regex for email validation