Hirvesh
Hirvesh

Reputation: 7982

Manipulating div size using jquery

i'm trying to change the size of a div to 99% of the original size in jquery.

I'm using the following code to get the width:

var textwidth = $('.comment-holder').css('width');

This outputs a value of 400px

So how can I set the width of this div to a new value, which is 99% of the original (of 400px)?

Upvotes: 2

Views: 456

Answers (3)

a'r
a'r

Reputation: 36999

It will be easier for you to use .width() rather than .css('width') as this returns a number. So something like the following should work:

var $e = $('.comment-holder'),
    width = $e.width();

$e.width(width * 0.99);

One problem with this, is that it will override css widths such as '90%' or '10em' and will therefore stop automatic scaling and re-sizing.

Upvotes: 1

Manish Trivedi
Manish Trivedi

Reputation: 3559

var w= $('.comment-holder').width(); //get width
w= w * 0.99 ;
$('.comment-holder').width( w); // set new width 

Upvotes: 0

Vivek Goel
Vivek Goel

Reputation: 24150

    Use .width call
newwidth=.9*textwidth;
$('.comment-holder').width(newwidth);

Upvotes: 0

Related Questions