Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: find overlapping elements between two result sets

Tags:

jquery

If I had two jQuery result sets, say

$("#someParent *")

and

$("#someElement").nextAll()

then how could I best get all the elements that occur in both result sets?

like image 821
Willem Mulder Avatar asked Jan 29 '26 15:01

Willem Mulder


1 Answers

You can use filter():

var firstSet = $("#someParent *");
var secondSet = $("#someElement").nextAll();
var elementsInBothSets = firstSet.filter(secondSet);
like image 173
Frédéric Hamidi Avatar answered Feb 01 '26 07:02

Frédéric Hamidi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!