suppose i have one js variable and my html data is stored into it like
var data = '<div id="tst">here will be my othere html</div>'
in this case can i determine that what would be height & width of div tst using jquery?
one guy give me solution like
var $test = $(data).appendTo('body');
var size;
window.setTimeout(function(){
size = {
height: $test.height(),
width: $test.width()
};
$test.remove();
});
but the above code looks bit complicated. if anyone know easy solution then please give me a sample code to do so. thanks
This code is enough:
Please note that it isn’t even necessary to use
size. You could put it into 2 variableswidthandheight. It is merely a personal preference.Also note that I prefer to use
.outerHeight()and.outerWidth()because the regular.width()/.height()don’t count the border. It’s up to you to decide which ones you actually need 😉