Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 73935

Set a background image for a button in html and then change the images from javascript

$
0
0

I am trying to set a background image for a button through html by using the following line:

<button> id="Flower" type="button" src="Images/Roses"></button>

Then I would like to be able to change its image by clicking another button to store an image file in an array (the array is needed because I want to store multiple images in an array to change multiple button background images) in java script by creating a function:

let images = [ ]
function insert(images) {
     images.push(images)
     document.getElementByID("Flower).src = Images[0]
}

In HTML another button would have the function as the onlclick:

<button type="button" onclick="insert(Images/Tulips)"></button>

It seems like I cant use an image file location as a parameter in a function. Is that correct?


Viewing all articles
Browse latest Browse all 73935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>