bengreene
10-22-2025Cloud Apps
Change an SVG color in BloX with criteria based on token - and for it to work with the carousel
Hello, my aim is to have a bar grow (change width, seems to be working fine) and change color based on if it exceeds a threshold. The issue is that the threshold will be client dependent. I have this...
- 11-07-2025
Hi bengreene​,
I got this response from one of our engineers. Can you take a look and let us know if it works for you?
"The issue is in the customer's script. They are using document.getElementById('conditional-bar').This method only returns the first found element in the DOM. Hence, their function only used once. They should use document.querySelectorAll instead, and cycle to colorize the bar."
"script": "(()=>{function customBarColoring(){var bars=document.querySelectorAll('#conditional-bar');if(!bars.length){setTimeout(customBarColoring,50);return}bars.forEach(function(b){var cbw=parseInt(b.getAttribute('width'));b.className.baseVal=cbw>=80?'conditional-bar-good':cbw>=65?'conditional-bar-meh':'conditional-bar-bad';});}customBarColoring();})();",