Need to update the CSS when the value changes? Give this a try:
var bar = $('#progressbar');
bar.change(function() {
$(this).css('opacity',parseInt($(this).val())/100);
});
UPDATE To style the strip that displays the value, I've made some significant changes to my answer. While I haven't explored manipulating CSS pseudo-selectors with jQuery or JavaScript, you can dynamically create and change a stylesheet. Here's an example:
$(document).ready(function() {
var style=document.createElement("style");
var sheet = document.head.appendChild(style).sheet;
var bar = $('#progressbar');
sheet.insertRule('progress::-webkit-progress-value{ background-color: rgb('+bar.val()+','+bar.val()+','+bar.val()+');}');
bar.change(function() {
sheet.deleteRule(0);
sheet.insertRule('progress::-webkit-progress-value{ background-color: rgb('+bar.val()+','+bar.val()+','+bar.val()+');}');
});
});
I haven't tested this code (just edited it here), but it gives a rough idea of what to do. Check out a working example with a "plus" button that changes the background color of the progress bar.
I'm disappointed by the limitations of HTML5 and JavaScript in this area, hopefully improvements will come in the future...
UPDATE2 Unfortunately, change()
for <progress>
doesn't work in jQuery for unknown reasons (although the real JavaScript object may have an onchange
property), so this example may not function as expected.
For an UPDATED DEMO, check it out!