Hjuster
Hjuster

Reputation: 11

How to get elements with the different value of the same attribute in javascript or jquery?

I need to find elements with the different value of the same attribute... This works-> $data.find("div[data-alpha='1']"); But i need something like this-> $data.find('div[data-alpha='1']' + 'div[data-alpha='2']' .... So i want to find all elements which have the ,,data-alpha" atribute 1 or 2. Anyone have an idea how to do that? Thanks for all answers! Cheers!

Upvotes: 1

Views: 500

Answers (3)

Emil
Emil

Reputation: 8527

If you want to find all elements with the data-alpha attribute use

$data.find([data-alpha])

If you need elements with specific values, use:

$data.find([data-alpha=x],[data-alpha=y])

Upvotes: 0

Tomas Brambora
Tomas Brambora

Reputation: 1046

Try the add() method (http://api.jquery.com/add/).

Upvotes: 0

user113716
user113716

Reputation: 322502

Use the multiple-selector[docs].

$data.find("div[data-alpha='1'], div[data-alpha='2']")

This allows you to accumulate the results of different selectors by joining the selectors with a comma into a single selector.

Upvotes: 4

Related Questions