JavaScript Can only change “stop-color” once with JavaScript

my function is as easy as this:

function changeColor(color, opacity, obj) {
    var colors = obj.getElementsByClassName("color_elem");

    for (var i = 0; i < colors.length; i++) {
        mainInterface.makeToast("Color " + i + ": " + color);
        colors[i].style.stopColor = color;
        colors[i].style.stopOpacity = opacity;
        //colors[i].setAttribute("stop-color", color);
        //colors[i].setAttribute("stop-opacity", opacity);
    }
}

This function can be called multiple times. It's triggered either from an button click event, or through an interface. As parameters it gets a color like#FFFFFF, an opacity ranging from 0 to 1 and an obj which in any case is an svg element.

When calling the function first, it changes the color like I would expect it. Calling it the second time, it won't. It will keep the color it was assigned by the first function call.

With mainInterface.makeToast("Color " + i + ": " + color); I ensured that I actually have the correct color, which i have.

I tried using css properties, aswell as attributes. (See comment)

Any ideas on that?

Answer:1

I have function in my code, which suppose to gradually decrease the refreshment of the page from 50 sec to 10 if the button is pressed. Here it is: <div id="signin" onclick="pgeReload()"></...

I have function in my code, which suppose to gradually decrease the refreshment of the page from 50 sec to 10 if the button is pressed. Here it is: <div id="signin" onclick="pgeReload()"></...

  1. retain value variable
  2. retain variable value in sas
  3. retain variable value in vba
  4. retain variable value in javascript
  5. retain variable value c#
  6. retain javascript variable value after postback
  7. retain value in global variable
  8. excel vba retain variable value
  9. python retain value of variable
  10. how to retain variable value in java

I want to visualize some timeseries data in the browser with jqplot. My problem is, that the x-axis values overlay and aren't readable. Therefore, the zoom function would be very useful. But it ...

I want to visualize some timeseries data in the browser with jqplot. My problem is, that the x-axis values overlay and aren't readable. Therefore, the zoom function would be very useful. But it ...

I want a hidden div on owl carousel. Please Help me . i am calling all css file from owl carousel . Here is my calling css file <link rel="stylesheet" href="<?php echo ...

I want a hidden div on owl carousel. Please Help me . i am calling all css file from owl carousel . Here is my calling css file <link rel="stylesheet" href="<?php echo ...

Does Angular sanitize all data when it gets rendered in the DOM automatically? ie, would this be safe: // using 'ngSanitize' angular.module('app', ['ngSanitize']); // somewhere in controller $http....

Does Angular sanitize all data when it gets rendered in the DOM automatically? ie, would this be safe: // using 'ngSanitize' angular.module('app', ['ngSanitize']); // somewhere in controller $http....