Andy
Andy

Reputation: 105

jQuery progressbar value not setting

I think I'm missing something really obvious here... must be... but for some reason I can't get my progressbar to display a value that's set in an attribute!

here's my html:

<div class="progressBar" data-value="58"></div>

and js:

$(function () {
    $('.progressBar').each(function () {
        $(this).progressbar();
        //var value = $(this).attr('data-value');
        //alert(value);
        $(this).progressbar('option', 'value', $(this).attr('data-value'));
    });
});

It displays the bar, but doesn't show any value (i.e. value = 0). If I hardcode a value into the js, it shows fine. If I uncomment the var value and alert line, I get an alert with the value. What am I missing??

Upvotes: 2

Views: 3335

Answers (4)

Eugine Joseph
Eugine Joseph

Reputation: 1558

In case, we dont get the first attempt. try like this:

$(function () {
  $('.progressBar').each(function () { 
    var thisValue = parseInt($(this).attr('data-value')); 
    $(this).progressbar({ value: thisValue });
  });
});

Upvotes: 0

Tats_innit
Tats_innit

Reputation: 34107

working demo http://jsfiddle.net/WQnqS/ or http://jsfiddle.net/WQnqS/1/

code

$(function () {
    $('.progressBar').each(function () {
        $(this).progressbar();
        //var value = $(this).attr('data-value');
        //alert(value);
        $(this).progressbar('option', 'value', parseInt($(this).attr('data-value')));
    });
});​

Upvotes: 2

Ram
Ram

Reputation: 144659

try this:

$(this).progressbar('option', 'value', parseInt($(this).data('value'),10));

Upvotes: 1

Denys S&#233;guret
Denys S&#233;guret

Reputation: 382102

You must parse your attr as int :

$(this).progressbar('option', "value", parseInt($(this).attr('data-value'), 10));

Upvotes: 4

Related Questions