简体   繁体   中英

How to get css width of class?

My question is, how can i get width parameter of class css style? For example i have <div class="page css-1" id="page1"> div with id=page and classes "page" and "css-1". I want to get width parameter of css-1 class style?

The easiest way is probably to ignore that <div> , create a new one with the class you care about and check its style attributes. You need to add it to the DOM for it to adopt the CSS of the document.

var div = $('<div>').addClass('css-1').hide();
$('body').append(div);
var width = div.css('width');
div.remove();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM