Jquery: code works, but is ugly
var ProdWidth = Math.abs(parseInt(Product.css('width')))
+ Math.abs(parseInt(Product.css('marginLeft')))
+ Math.abs(parseInt(Product.css('marginRight')))
+ Math.abs(parseInt(Product.css('paddingLeft')))
+ Math.abs(parseInt(Product.css('paddingRight')));
This works for coming up with the total width of an element including padding and margins, but its stupid. How should I b开发者_运维技巧e doing it?
Check out the outerWidth()
property. It gets the width of the element and its padding, border, etc.
Setting its first argument to true
will include the margins.
var ProdWidth = Product.outerWidth(true);
精彩评论