admin管理员组

文章数量:1287891

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?

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?

Share Improve this question edited Aug 22, 2011 at 14:34 Jan Turoň 32.9k23 gold badges137 silver badges177 bronze badges asked Apr 30, 2011 at 12:10 FaraonaFaraona 1,7002 gold badges22 silver badges33 bronze badges 1
  • 1 possible duplicate of get style.width when property set with className – Shakti Singh Commented Apr 30, 2011 at 12:16
Add a ment  | 

1 Answer 1

Reset to default 10

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();

本文标签: javascriptHow to get css width of classStack Overflow