-1

How can I select a DOM element that has two data- attributes matching my values using jQuery? My element is

<a data-published="true" data-i ="3"></a>

I need to select this element.

2
  • So, whats the issue and conditional? Commented Aug 16, 2018 at 13:21
  • $('a[data-published=true][data-i=3]') u can use it like this Commented Aug 16, 2018 at 13:27

2 Answers 2

2

It will be a[data-published="true"][data-i ="3"]

var $el = $('a[data-published="true"][data-i ="3"]');
console.log($el.length);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a data-published="true" data-i ="3"></a>

Sign up to request clarification or add additional context in comments.

1 Comment

You may help the community more by flagging the dup question instead of answering them...
1
$('a[data-published="true"]').val

so on your code.. if you want to match both then

$('a[data-published="true"][data-i="3"]').val

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.