Home > front end >  Turn to cycle a lot a div, how to obtain a single div following the number of elements
Turn to cycle a lot a div, how to obtain a single div following the number of elements

Time:10-03


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>



CodePudding user response:

tag element ah,,,, $(". The parent element. Child elements"). The length; Jquery written

CodePudding user response:

to solve the problem, and I hope eldest brother can give some points,,, need points here,,, thank you

CodePudding user response:

reference 1st floor Logerlink response:
 


<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>





Java write

CodePudding user response:

Jq is the fastest to get $div in circulation all get div to print his child; Or when you are in the loop index + dynamic plus class used to identify a corresponding to the div and then directly $(' XXX + index). It is good to the child the

  • Related