-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
  • 129,808
  • 12
  • 152
  • 166
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
  • 34,922
  • 8
  • 55
  • 102
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,223
  • 8
  • 31