Suppose I have this html structure:
<div class="block_right"> <h1>block 1</h1> <div class="object_div"> <p>title 3</p> <div><a class="play" id="p3">play</a></div> </div> <div class="object_div"> <p>title 2</p> <div><a class="play" id="p2">play</a></div> </div> <div class="object_div"> <p>title 8</p> <div><a class="play" id="p8">play</a></div> </div> <div class="object_div"> <p>title 12</p> <div><a class="play" id="p12">play</a></div> </div> </div> I need using jquery , having clicked on one of the play buttons, to find the next and previous play button. You also need to select the next element from exactly this block class="block_right" , and on the page there can be a similar block like class="block_left" and other objects, which can randomly coincide with the current block. Of course, you cannot choose from it, only from the current one
next() does not fit, since, as you can see, the play buttons are not consecutive. You can of course find the parent div , which in my example has class="object_div" then find its next neighbor, and then look for this next neighbor with a child of the play class. But this solution is not convenient, because creates a dependence of js on the layout structure of the excess, and it can change.
I think the solution may be to select all the elements with the play class child for block_right and from them choose the element next for the current one. How to do this right?