Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select all elements between two specific elements

Tags:

jquery

I need to select all a tags from <a class="self"> to <a class="next">. Here is example

<span class="pages">
    <a class="prev">&nbsp;</a>
    <a>13</a>
    <a>14</a>
    <a>15</a>
    <a>16</a>
    <a class="self">17</a>
    <a>18</a>
    <a>19</a>
    <a>20</a>
    <a>21</a>
    <a class="next">&nbsp;</a>
</span>

There are hrefs attributes. I don't want to get anything before class self. I want everything from self to end of the span element.

like image 788
user1119200 Avatar asked Aug 25 '26 05:08

user1119200


1 Answers

nextUntil [docs] would get all a elements between a.self and a.next, excluding them:

$('a.self').nextUntil('a.next', 'a');

If you want to include them, just use .nextAll [docs]:

$('a.self').nextAll('a').andSelf();
like image 127
Felix Kling Avatar answered Aug 27 '26 21:08

Felix Kling