get CSS rule's percentage value in jQuery

后端 未结 12 1461
一个人的身影
一个人的身影 2020-11-22 08:22

Let\'s say the rule is as follows:

.largeField {
    width: 65%;
}

Is there a way to get \'65%\' back somehow, and not the pixel value?

12条回答
  •  一整个雨季
    2020-11-22 08:31

    There's no built-in way, I'm afraid. You can do something like this:

    var width = ( 100 * parseFloat($('.largeField').css('width')) / parseFloat($('.largeField').parent().css('width')) ) + '%';
    

提交回复
热议问题