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