-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.

Satpal
  • 132,252
  • 13
  • 159
  • 168
Faisal Rashid
  • 368
  • 1
  • 11

2 Answers2

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>
void
  • 36,090
  • 8
  • 62
  • 107
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
Avi
  • 1,424
  • 1
  • 11
  • 32