Reputation: 261
I want to take the value from the division of two jquery variables and use it to change the width of a div.
I think the problem is here animate({width:'"+percent+"%'});
here is the jquery:
var x = 56;
var y = 64
var percent = Math.ceil((x/y)*100);
$(".box").animate({width:'"+percent+"%'});
here is the html:
<div class="box"></div>
Upvotes: 1
Views: 242
Reputation: 12775
var x = 56;
var y = 64
var percent = Math.ceil((x/y)*100);
$(".box").animate({width: percent + "%"});
Here is jsFiddle : http://jsfiddle.net/Bz4hC/1/
Upvotes: 1
Reputation: 206
var x = 56; var y = 64: var percent = Math.ceil((x/y)*100);
percent will always be 100%
Upvotes: 0
Reputation: 388316
Your string concatenation is the problem, just do
$(".box").animate({
width: percent + '%'
});
Upvotes: 2