pre
class を持つ 10 個の要素を含む次のマークアップがありますindent
。
<pre class="indent"></pre>
<pre class="indent"></pre>
<pre class="indent"></pre>
<pre class="indent"></pre>
<pre class="indent"></pre>
<pre class="indent"></pre>
<pre class="indent"></pre>
<pre class="indent"></pre>
<pre class="indent"></pre>
<pre class="indent"></pre>
次の jQuery.each()
関数を使用して、各要素を反復処理しています。
$(function(){
$.each(".indent", function(index){
alert(index);
});
});
10 個のアラートが表示されるはずですが、7 個しか表示されません
ただし、これは次の場合に期待どおりに機能し$(".indent").each()
ます。
$(function(){
$(".indent").each(function(index){
alert(index);
});
});
ドキュメントを見ると$.each()
、違いがあることがわかります。
$.each() 関数は、jQuery オブジェクトを排他的に反復処理するために使用される $(selector).each() と同じではありません。
しかし、この場合、すべての要素を反復処理しない理由がわかりません。
なぜこうなった?