Firefox won't change image source

I am trying to change the image in JavaScript + Prototype by changing the src attribute of this element. It works fine in IE, but not in Firefox. I get no errors and the script continues to execute after this bit is executed:

var image = $('toggle'); image.setAttribute("src", "../images/icons/icon_minus.gif"); image.setAttribute("alt", "Minus Symbol"); image.setAttribute("title", "Collapse tree"); 

What am I doing wrong? How to make the browser replace the existing image "icon_plus.gif" with "icon_minus.gif"? I am sure that this should be something really obvious, but I can’t understand that!

thanks

+1
source share
2 answers

I can’t understand what’s wrong, but I believe that it can be done:

 image.src = "../images/icons/icon_minus.gif"; 

By the way, is the image path absolutely correct?

+1
source

This function works fine in all browsers (Chrome, Firefox, IE, Edge, ...):

 function recaptcha() { $("#captcha-img").attr('src', ""); setTimeout(function(){ $("#captcha-img").attr('src', "captcha?"+new Date().getTime()); }, 0); } 

The important point is to create a new URL that causes FF and IE to re-display the image.

0
source

Source: https://habr.com/ru/post/922119/


All Articles