1

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?

2 Answers 2

3

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

$(array_two).filter(array_one.join(","));
Sign up to request clarification or add additional context in comments.

2 Comments

@Christoph: I don't see why it won't work... can you explain in more detail?
my bad, missed the "," concatenation, thought it was " " at the first glance.
0

Assuming array_two is a jQuery object you can do:

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.