Reputation: 4245
I have a variable perc
which is a number that changes from 0 to 100. When I use jquery to adjust the width of a progress bar it just does it in pixels.
var perc = ((first/constant)*100).toFixed(0);
.width(perc)
How can I do it as a percentage?
Upvotes: 3
Views: 2804
Reputation: 195952
add the %
symbol after the number
.width(perc+'%')
If you read the documentation of the .width(value)
method you will see that it accepts both numbers and strings..
If a string is provided, however, any valid CSS measurement may be used for the width (such as
100px
,50%
, orauto
).
Upvotes: 5