How many items have the class myElement
? Consider using an id
, not a class
, as getting the width of two elements is not really possible (or logically understandable IMO).
I made a little demo, and for me, it outputs the width in pixels for a single span
element with a width of 100%
(for me, it alerts something around 400
): http://jsfiddle.net/LqpNK/3/.
By the way, <span>
element's can't have a set width or height, so setting their width and height does you no good. Instead, display them as a block
element (so just replace <span>
with <div>
, or add display: block;
to the CSS of .myElement
).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…