get CSS rule's percentage value in jQuery

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

    You could put styles you need to access with jQuery in either:

    1. the head of the document directly
    2. in an include, which server side script then puts in the head

    Then it should be possible (though not necessarily easy) to write a js function to parse everything within the style tags in the document head and return the value you need.

提交回复
热议问题