1
2 & lt;/span>
3
4 & lt;/span>
5 & lt;/span>
6 & lt;/span>
7 & lt;/span>
8 & lt;/span>
9 & lt;/span>
If direct write $(" div & gt; Span "). The length that is nine, can inquire how to get to span across multiple div number is 4 31 respectively
CodePudding user response:
First traversal div, then traverse span
<script SRC="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquery.js" & gt; </script>
<script>
$(function () {
Var divs=$(" div ");
Divs. Each ((index, item)=& gt; {
Var spans=$(item). Find (" span ") | | '.
If (spans! .==") the console log (spans. Length);
});
})
</script>
<body>
1
2 & lt;/span>
3
4 & lt;/span>
5 & lt;/span>
6 & lt;/span>
7 & lt;/span>
8 & lt;/span>
9 & lt;/span>