Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery prevUntil() include start selector and end selector

I would like to select the start and end selector for the prevUntil() or nextUntil() jQuery selector methods. If I implement these methods now, it grabs everything between the two selectors given.

i.e. $('p').prevUntil('h1') will not include the p and h1 element, only those between them. How could I also select the p and h1 elements as well as though between?

like image 511
Globalz Avatar asked May 05 '10 04:05

Globalz


1 Answers

Take a look at the .addBack method to add the results of the previous selector to the current matches. Combining that with the .prev method seems to do the trick:

$('p').prevUntil('h1').addBack().prev('h1').addBack();
like image 102
David Fullerton Avatar answered Oct 01 '22 18:10

David Fullerton