Is there a way to know the size of a potential DOM node?
.square{ width: 100px; height: 100px; } var h = $('<div/>', {class: 'square'}); alert($(h).width()); // => 0 Is there a way to know the size of a potential DOM node?
.square{ width: 100px; height: 100px; } var h = $('<div/>', {class: 'square'}); alert($(h).width()); // => 0 paste it into the dom with position absolute; and remove immediately.
var h = $('<div/>', {class: 'square'}); h.appendTo('body'); h.css('position','absolute'); var w=h.width(); h.detach(); h.css('position',''); $('#out').text(w); //в пикселях console.log(h) http://jsfiddle.net/oceog/PSLbC/
if you just need to write to the current css, you can
var w=h.css(width); //вставлять в этом случае надо только если есть возможность наследования свойства css элементом Source: https://ru.stackoverflow.com/questions/330454/
All Articles