2

$.eachクラス名で選択されたDOM要素のコレクションの高さを計算するためにjQueryの最新バージョンで使用しています。

$.each($('.some-class'), function() {
  console.log($(this).height());
}

640、657、334、487 という高さの値のリストが表示されます。

ただし、コンソールに入って最初の高さを計算すると、代わりに正確な が$('.some-class').first().height()得られます。553

$.each で何が起こっているのですか? $(this)で確認すると正しいものを選択しているようconsole.log($(this))です。

4

2 に答える 2

0

.height() always returns the content height, It won't care about css box-sizing property. If you have or don't have box-sizing:border-box it does not include the padding and margin.

You can use .css( "height" ) instead of .height()

于 2013-09-18T19:28:07.933 に答える