For example I might have some css stuff that looks like this:
.divType1 {
position: absolute;
width: 60px; height: 60px;
left: 400px; top: 100px;
border: 1px solid #89B;
z-index: 0;
}
Now within Javascript I want to gather div class divType1' css attributes, but am provided only with the div class, so I can't do something of form ( pseudo-code ):
selectDivWithClass( divType1 ).getCss(left).
I could hack something by instantiating a div with class divType1 and grab its css attributes, and then destroy it, but is there a better way?
The original question has some ambiguity, resulting in lots of good answers that will work in other settings. So here's the restated one:
Using Javascript, how do I gather a subset of a div class' css attributes specified by the maker in the stylesheet, so no browser defaults. Furthermore, assume only 'plain-vanilla' attributes will appear in the css. So stuff like width, height, not stuff like:
transition: width 2s;
-moz-transition: width 2s; /* Firefox 4 */
-webkit-transition: width 2s; /* Safari and Chrome */
-o-transition: width 2s; /* Opera */
I am given nothing but the class name, so I am not given a list of attributes I need to collect before hand.
Finally, the function ideally should return an object mapping style attribute to value.
In the scope of what I am trying to do, the problem is solved by @RobG's answer below.