[英]How to get css width of class?
My question is, how can i get width parameter of class css style?我的问题是,如何获得 class css 样式的宽度参数? For example i have
<div class="page css-1" id="page1">
div with id=page and classes "page" and "css-1".例如,我有
<div class="page css-1" id="page1">
div,id=page 和类“page”和“css-1”。 I want to get width parameter of css-1 class style?我想获取css-1 class 样式的宽度参数?
The easiest way is probably to ignore that <div>
, create a new one with the class you care about and check its style attributes.最简单的方法可能是忽略
<div>
,使用您关心的 class 创建一个新的并检查其样式属性。 You need to add it to the DOM for it to adopt the CSS of the document.您需要将其添加到 DOM 以使其采用文档的 CSS。
var div = $('<div>').addClass('css-1').hide();
$('body').append(div);
var width = div.css('width');
div.remove();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.