Padding or margin value in pixels as integer using jQuery

后端 未结 14 2123
陌清茗
陌清茗 2020-11-28 02:40

jQuery has height() en width() functions that returns the height or width in pixels as integer...

How can I get a padding or margin value of an element in p

相关标签:
14条回答
  • 2020-11-28 03:29

    Don't use string.replace("px", ""));

    Use parseInt or parseFloat!

    0 讨论(0)
  • 2020-11-28 03:30

    This simple function will do it:

    $.fn.pixels = function(property) {
        return parseInt(this.css(property).slice(0,-2));
    };
    

    Usage:

    var padding = $('#myId').pixels('paddingTop');
    
    0 讨论(0)
提交回复
热议问题