This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Custom javascript function change color of svg icon
#1
Hi,

I would like to change the color of the svg icon in visualisation based on it's value.
On the internet I found that the css attribute 'fill' should do the job but it doesn't.
The script itself works, if I alter it to change the background of the 'icon' element, it changes color accordingly.
Code:
icon.css('background-color', color);

How can I make it changes the color of the svg?

Code:
$(function() {
  $('.bgcolor-by-value').each(function(i, el) {
    var $el = $(el), addr = $(el).data('object'), icon = $el.find('.icon');
    if (addr) {
      grp.listen(addr, function(obj) {
      console.log(icon.get(0), obj.value);
        var value = obj.value
          , color = 'green'; // default color

        if (value >= 3 && value <= 4) {
          color = 'orange';
        }
        else if (value >= 5) {
          color = 'red';
        }

        icon.css('background-color', color);
      });
    }
  });
});

Thanks!
Reply


Messages In This Thread
Custom javascript function change color of svg icon - by tigi - 29.12.2021, 13:29

Forum Jump: