Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't change the src of a image with JavaScript

Im triying to change the source of a image with a js function but it seems to not work, the function executes on a mounted() of Framework7

This is what i have right now

HTML:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<div>
 <span> <img id="star_1" class="star" src="../assets/empty_star.png"> </span>
 <span> <img id="star_2" class="star" src="../assets/empty_star.png"> </span>
 <span> <img id="star_3" class="star" src="../assets/empty_star.png"> </span>
 <span> <img id="star_4" class="star" src="../assets/empty_star.png"> </span>
 <span> <img id="star_5" class="star" src="../assets/empty_star.png"> </span>
</div>

JS:


setStars(){

 var full_star = '../assets/full_star.svg';

 document.getElementById('star_1').src = full_star;
 document.getElementById('star_2').src = full_star;
 document.getElementById('star_3').src = full_star;
 document.getElementById('star_4').src = full_star;                       
 document.getElementById('star_5').src = full_star;
}

This keeps me the empty stars and i wanna change them depending of a rating, how can i fix it?

Image of what im getting right now

I also tryed to get the document.getElementById in var but still does not work

>Solution :

document.querySelectorAll('.star')
  .forEach(el => el.src = '/assets/full_star.svg'');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading