Prabhakar rai Prabhakar rai - 5 months ago 14
HTML Question

Change only one character of all img src of a class using javascript

I want to change the src of all the images which are in the 'car-image' class.

But I do not have to change whole url. I just want to change one character.

I want edit this -

<div class="car-image">
<img src="/cars/3_large_1.png">

To this-

<div class="car-image">
<img src="/cars/3_large_2.png">

And this format is common in all the image in this class.
I tried something like this-

var allsrc = document.getElementsByClassName('car-image');

This is not working.
How can i do this in javascript?


you are setting src of wrong node allsrc returns your div not the image.

Try this