Padding or margin value in pixels as integer using jQuery

后端 未结 14 2185
陌清茗
陌清茗 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:08

    You can just grab them as with any CSS attribute:

    alert($("#mybox").css("padding-right"));
    alert($("#mybox").css("margin-bottom"));
    

    You can set them with a second attribute in the css method:

    $("#mybox").css("padding-right", "20px");
    

    EDIT: If you need just the pixel value, use parseInt(val, 10):

    parseInt($("#mybox").css("padding-right", "20px"), 10);
    

提交回复
热议问题