Take the 2-minute tour ×

I have a small question concerning css styles and javascript / jquery. Lets say i define the following css style.

.myStile { padding: 5px }

Now I'd like to access the property of padding while not writing an html element to the document. I came up with the following idea which only works with Firefox (IE and Chrome say NaN)

var div = $('<div class="myStile />');
var padding = parseInt(div.css('padding-left'), 10);

is there a way to make this work in IE and Chrome (well trident and webkit I guess) as well? I know that one's able to read whole css files via javascript (and get the class, the properties and so on ...), but that seems to be a bit overkill.

share|improve this question
hallo dänu! here is a question i asked a while ago. I think you can get your answers there! stackoverflow.com/questions/1285033/… –  meo Jun 8 '10 at 10:16
add comment

1 Answer

up vote 0 down vote accepted

Thanks meo for your comment. This post answers the question. Here's a google find which answers the "other browsers than chrome, firefox, safari" issue.

share|improve this answer
add comment

Your Answer


