I have the following markup containing 10 pre
elements with the class 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>?
I'm using the following jQuery .each()
function to iterate through each element:
?$(function(){
$.each(".indent", function(index){
alert(index);
});
});?
I would expect to see 10 alerts, however I only see 7
However, this works as expected with $(".indent").each()
:
$(function(){
$(".indent").each(function(index){
alert(index);
});
});?
Looking at the $.each()
documentation, I understand theres a difference:
The $.each() function is not the same as $(selector).each(), which is used to iterate, exclusively, over a jQuery object.
But I don't understand why in this instance, it doesn't iterate through all elements.
Why is this happening?
See Question&Answers more detail:os