The code is as follows:
Copy Code code as follows:
<div id= "Div1" >
<span>a</span>
<span>b</span>
<span>c</span>
</div>
1. Wrong way : cannot use [] way to take jquery object array, as follows:
Copy Code code as follows:
$ (function () {
var Div_span = $ ("#div1 span");
for (var i = 0; i < div_span.length; i++) {
Div_span. [I].html (i);
}
});
This is not valid.
2. a jquery eq () method can be used to select:
Copy Code code as follows:
for (var i = 0; i < div_span.length; i++) {
Div_span.eq (i). html (i);
}
3. You can use each () method to traverse :
Copy Code code as follows:
$ (function () {
var Div_span = $ ("#div1 span");
var i = 0;
Div_span.each (function () {
$ (this). HTML (i);
i++;
});
});
When each () is traversed, if you get a jquery object with $ (this), if you use this directly, you get a DOM object
4. The pure JS code obtains the DOM object array , may obtain the array element by [] the way
The back 3 is the right way, the first one is wrong, put him in the first, is because to emphasize, the future can not make the same mistake, the small partners can be seen carefully ha.