Sven
Sven

Reputation: 13295

Comparing two arrays in jQuery regarding CSS classes

I have two arrays. One looks like this:

var array_one = [".a", ".b", ".c", ".d"];

.a, .b, .c & .d are CSS-classes that can be found in the DOM.

Then I got another array array_two which holds all elements with class .lorem currently in the DOM.

Now how do I find the elements that have .a, .b, .c or .d and .lorem by comparing the two arrays?

Upvotes: 1

Views: 107

Answers (2)

Naftali
Naftali

Reputation: 146310

Assuming array_two is a jQuery object you can do:

array_two.has(array_one.join(","));

This is using the .has(...) jQuery function.

Upvotes: 0

Matt
Matt

Reputation: 75317

You can use the jQuery's filter() method, coupled with Array's join();

$(array_two).filter(array_one.join(","));

Upvotes: 3

Related Questions