Find 2 date attributes in a single element

Asked

Viewed 79 times

5

How can I find a particular attribute that contains another specific attribute? for example:

<a class="fc-draggable" data-belongs="3" data-target="2"></a>

I can select all elements that contain a certain attribute using:

$('*[data-belongs="3"]');

But how do I select all data-belongs='2' containing data-target='3'?

  • 2

    Have you tested $('[data-belongs="2"][data-target="3"]');?

  • http://answall.com/a/67901/129

  • @Sergio if you want to select everyone who não tenham this attribute as I would do? $('a[data-belongs]').not('[data-belongs="'+current+'"][data-target="'+target+'"]').hide(); ?

  • Exactly... that would work

  • @Sergio, post the answer for me to confirm!

2 answers

4

3


You can use $('[data-belongs="2"][data-target="3"]'); as I mentioned in comment, so you search for elements with both attributes.

To select through the element attributes we can use the attribute selectors followed by each other.

To filter later we can use the .not() thus:

$('a[data-belongs]').not('[data-belongs="' + nr + '"][data-‌​target="' + nr + '"]‌​').hide();

Example: https://jsfiddle.net/k9h3kka3/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.