How can i get height
and width
of element which doesn't a part of DOM yet?
For example:
var t = $('<div style="position:absolute;height:100px;wid开发者_开发百科th:100px;background-color:steelblue;" >lalala</div>');
var height = t.height(); // height is 0!
Works for me as well. You could try
var height = t.innerHeight();
though as demonstrated in this fiddle.
If that doesn't work for you (well possible depending on the browser), consider temporarily adding the element to the DOM:
var t = $('<div style="position:absolute;height:100px;width:100px;background- color:steelblue;" >lalala</div>').hide().appendTo('body');
var height = t.height();
t = t.detach().show();
精彩评论