3
1.4.4隠された要素の返り値ですが、別の隠し要素の要素はどうでしょうか? getWidthより良い解決策はありますか?隠された親を持つ要素のサイズを取得する方法は?
<script type="text/javascript">
function getWidth(element){
var parent = element.parent();
$('body').append(element);
var width = element.width();
parent.append(element);
return width;
}
$(function(){
var width = $("#foo").width();
console.log(width); //0
width = getWidth($("#foo"));
console.log(width); //ok
});
</script>
<div style='display:none'>
<div style='display:none' id='foo'>bar</div>
</div>
参照http://stackoverflow.com/questions/1841124/find-the-potential-width-of-a-hidden-element – Flo