84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
The entire code is dynamically added to the page through js. When b changes, how to get the position (position) of a among all a's on the page?
<p class="a"> <p class="b"></p> </p>
I don’t quite understand what it means
If the class name of a is unchanged, use jQuery directly
$(".a").index(this.parent())
where this is the changed b
[...document.querySelector('.b').parentNode.parentNode.children].indexOf(document.querySelector('.b').parentNode)
Since it is added dynamically, why not give it an identifier before adding it to the dom? For example:
<p class="a" index="1"> <p class="b"></p> </p> <p class="a" index="2"> <p class="b"></p> </p> ...
In this way, when b changes, just get the parent’s index attribute directly
I don’t quite understand what it means
If the class name of a is unchanged, use jQuery directly
$(".a").index(this.parent())
where this is the changed b
Since it is added dynamically, why not give it an identifier before adding it to the dom? For example:
In this way, when b changes, just get the parent’s index attribute directly