0

I have run into an issue where i want to filter with multiple data attributes using jquery find.

I have the following dom elements:

<span data-selected="no" data-position="y2016m2" data-type="project" data-workplaceid="113" data-languageid="5" data-industryid="3" data-id="pr15" class="month-item dark-text timeline-item project-item"></span>

<span data-selected="no" data-position="y2016m5" data-type="project" data-workplaceid="113" data-languageid="1" data-industryid="5" data-id="pr22" class="month-item dark-text timeline-item project-item"></span>

<span data-selected="no" data-position="y2016m6" data-type="project" data-workplaceid="113" data-languageid="3" data-industryid="3" data-id="pr13" class="month-item dark-text timeline-item project-item"></span>

<span data-selected="no" data-position="y2017m2" data-type="project" data-workplaceid="113" data-languageid="1" data-industryid="1" data-id="pr1" class="month-item dark-text timeline-item project-item"></span>

<span data-selected="no" data-position="y2018m4" data-type="project" data-workplaceid="113" data-languageid="5" data-industryid="2" data-id="pr75" class="month-item dark-text timeline-item project-item"></span>

I am trying to use the following negating statement to get rid of all the items that are not needed:

$('.timeline').find('.project-item[data-languageid!=5][data-industryid!=3]');

The problem with this statement and its behaving as an OR statement and not as an AND statement. So when i run this line of code i get the first element from the list and the third but the third elements data-industryid=3 so it shouldnt be there.

My question is that the double data attribute statement filtering works as an OR statement or as an AND cause how i see here it is working as an OR statement cause on of the id's is the same.

Any advice would be much appreciated. Thanks Trix.

1 Answer 1

1

Use .not() or :not()

$('.timeline').find('.project-item:not([data-languageid=5][data-industryid=3])');

Or .not

$('.timeline').find('.project-item').not('[data-languageid=5][data-industryid=3]');

you can also use :not():not()

 $('.timeline').find('.project-item:not([data-languageid=5]):not([data-industryid=3])');
Sign up to request clarification or add additional context in comments.

3 Comments

Good god that solved it! Been at it for a while. Many thanks!
you're totally welcome @trix87 .. you can use the :not selector as you want up to your need as I explained on my answer .. Have a great day :-)
Will accept the answer in 5 mins. Have a great day!

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.