Die 20
Die 20

Reputation: 261

Animating a div by width using a jquery variable

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

Answers (3)

Alexander
Alexander

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

Daniel E.
Daniel E.

Reputation: 206

var x = 56; var y = 64: var percent = Math.ceil((x/y)*100);

percent will always be 100%

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388316

Your string concatenation is the problem, just do

$(".box").animate({
    width: percent + '%'
});

Upvotes: 2

Related Questions