This works:
<a href="#/link1">link1</a>
<a href="#/link2">link2</a>
<a href="#/link3">link3</a>
$("a[href*='#/link1'").next('a[href*="#"]').click();
but this does not:
<a href="#/link1">link1</a><br>
<a href="#/link2">link2</a><br>
<a href="#/link3">link3</a><br>
$("a[href*='#/link1'").next('a[href*="#"]').click();
The above tests the “< br >” tag, not the next matching link.
How would I go about making it work in both situations. I want to select the next matching element, not the next element if it matches. Maybe .next() isn’t the correct method?
The second example should not select anything at all. Read the documentation of
next:You have to use
nextAllto get all siblings and filter them accordingly:Reference:
nextAll