Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

set background image javascript

//Dynamically set the background image using js

let imageLink = 'https://images.pexels.com/photos/3928264/pexels-photo-3928264.jpeg?auto=compress&cs=tinysrgb&w=600&lazy=load'
document.getElementById(
    'body'
  ).style.backgroundImage = `url(${imageLink})`;
//Note that the url is encompassed by backticks, not single quotations.
//Backticks can be gotten on keyboard 
//You can build a function and make imageLink a parameter or do anything else. 
//There are many thinngs
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #set #background #image #javascript
ADD COMMENT
Topic
Name
2+1 =