I've set up a simple jQueryUI progressbar:
<script type="text/javascript">
$(function() {
$("#progressbar").progressbar({
value: 35
});
});
</script>
<div id="progressbar"> </div>
Now, I'd like to color the of the bar based on it's value (e.g. <10 red, <50 yellow, >50 green). How do I do this?
Note: There are similar questions, but the answers were not clear enough to help me get things done. Hopefully, someone can point out an easier way or provide more detailed instructions. Thanks.
jQuery Progressbar uses CSS and images.
Your Stackoverflow answer says the same:
In order to change the color you would have to modify the png image.
Or as written above you could copy the image add a second class and add them using jquery:
Because the working example on the accepted answers seems not to be working, I leave this one based in his answer in case anyone finds it useful.
https://jsfiddle.net/benjamintorr/a1h9dtkf/
I fiddled around with it and here's what I found. Using jQuery UI v1.8rc3, I can override the theme colors for the progress bar.
alt text http://i42.tinypic.com/mt5v6p.jpg
Here's how: When you add a progressbar widget to a div, with something like:
...the jQuery UI progressbar creates a div within your div; this inner div represents the value bar. To set the color of the bar, set the background of the child (inner) div.
You can also set the color of the empty space in the progress bar, the space to the right of the value bar. Do this by setting the background of the outer div.
For either of these, you can use flat colors, or images. If you use images, then be sure to set the repeat-x. The code to do that, looks like this:
html:
js:
ok, that takes care of setting the colors. Now, if you want to dynamically set the color of the bar as the value changes, you hook the progressbarchange event, like this:
Working demonstration: http://jsbin.com/atiwe3/3
Note:
If you want to override the colors for all progressbars the css classes to use are
ui-widget-content
, for the "background" or outer div, andui-widget-header
for the actual bar (corresponding to the inner div). Like this:If you eliminate the
.ui-progressbar
prefix, it will override the colors of all UI widgets, including progressbars.Use the following code:
One simple thing would be when you are initializing the progress bar with values in your js you do :
Since you want different colors for different progressbars, you can do :
I hope this answers your question. I tried doing what the guy has said in the first answer, but could not get it to work so tried this and it started working.