get CSS rule's percentage value in jQuery

后端 未结 12 1579
一个人的身影
一个人的身影 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:52

    You can use the css(width) function to return the current width of the element.

    ie.

    var myWidth = $("#myElement").css("width");
    

    See also: http://api.jquery.com/width/ http://api.jquery.com/css/

提交回复
热议问题