jQuery How to Get Element's Margin and Padding?

前端 未结 8 2197
感动是毒
感动是毒 2020-12-02 09:20

Just wondering - how using jQuery - I can get an elements formatted total padding and margin etc ? i.e. 30px 30px 30px 30px or 30px 5px 15px 30px etc

I tried

<
8条回答
  •  渐次进展
    2020-12-02 09:29

    According to the jQuery documentation, shorthand CSS properties are not supported.

    Depending on what you mean by "total padding", you may be able to do something like this:

    var $img = $('img');
    var paddT = $img.css('padding-top') + ' ' + $img.css('padding-right') + ' ' + $img.css('padding-bottom') + ' ' + $img.css('padding-left');
    

提交回复
热议问题