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% 开发者_JAVA技巧of the original (of 400px)?
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.
Use .width call
newwidth=.9*textwidth;
$('.comment-holder').width(newwidth);
var w= $('.comment-holder').width(); //get width
w= w * 0.99 ;
$('.comment-holder').width( w); // set new width
精彩评论