Setting An Image Src Via Javascript

Does setting an image src via javascript not work?

I’ve tried the following code embedded before and although I can GET the image src, it will never SET it.

var i = 0; // Start Point
var splashImageList = ; // Images Array
var time = 3000; // Time Between Switch

// Image List
splashImageList[0] = “”;
splashImageList[1] = “”;
splashImageList[2] = “”;
splashImageList[3] = “”;

// Change Image
function changeImg(){
document.getElementById(“splashImg”).src = splashImageList[i];

// Check If Index Is Under Max
if(i < splashImageList.length - 1){
  // Add 1 to Index
} else { 
	// Reset Back To O
	i = 0;

// Run function every x seconds
setTimeout("changeImg()", time);


// Run function when page loads

Thanks in advance.

hi @Scott_Mire you can try this simple example

let splashImageList = [
let idx = 0;
let isCurrentSrc = "";

const myFunction = () => {
  isCurrentSrc = splashImageList[idx];
  idx += 1;
  if (idx > splashImageList.length) {
    idx = 0;
//  console.log(isCurrentSrc);

setInterval(myFunction, 3000)

I have made for you working example with extra bits to have something to start with.

Hope this will solve your request

Thanks for the reply!!
I tried your code…but Webflow seems to not allow you to set the image src. It gets it, but won’t set it. I know the code is right, but it just doesn’t work in Webflow.

Hey Scott, not sure what you’re talking about.
Of course you can update an image src with script, and it’s super easy.

Client-side script has nothing to do with Webflow, anyway, Your scripts execute in the browser after Webflow has delivered the page. It’s not involved.

Share your read-only project link and a link to your published site ( is fine ), and we’ll have a look.

ok then @Scott_Mire here is simple example in WF.


Live Preview

PS: you can just use any slider for that , even WF prediefined.

I finally figured out what the problem was…

The image src and alt were, in fact, being changed, but the image was set to “responsive” in Webflow and thus the image source set was included and NOT being changed. By unchecking the “responsive” option in Webflow, the image is then determined by the src, not the srcset.

Thanks so much to everyone for the help! You are awesome!

jhi @Scott_Mire if issue doesn’t persist feel free to close your request as solved.