Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery add width + padding;

Tags:

jquery

i am trying to do var width = ($(this).width() + $(this).css('padding-left') + $(this).css('padding-right'));

do add the width to the padding, so i should end up with width = 200 + 4 + 4 = 208 instead i end up with 2004px4px;

how can i force it to add them to get 208?

like image 455
Hailwood Avatar asked Aug 23 '10 03:08

Hailwood


2 Answers

Why dont you use outerWidth property instead. http://api.jquery.com/outerWidth/

like image 127
vinay Avatar answered Nov 14 '22 16:11

vinay


Use parseInt

var width = $(this).width();
var paddingLeft  = parseInt($(this).css('padding-left' ), 10);
var paddingRight = parseInt($(this).css('padding-right'), 10);

var paddedWidth = width + paddingLeft + paddingRight;

Or better use the jSizes plugin as mentioned in this answer.

like image 43
Anurag Avatar answered Nov 14 '22 16:11

Anurag