0

I've got some div tags with diffrent data attributes, for example ,

<div class="sh_content" id="sh_content_3" data-price="price_1" data-capacity="capacity_1" data-debit="debit_3">
<!-- Content --->
</div>
<div class="sh_content" id="sh_content_2" data-price="price_1" data-capacity="capacity_2" data-debit="debit_2">
    <!-- Content --->
    </div>

Using js or jquery, how can I find the "div" tag that contains values "price_1,capacity_1,debit_2". I searched long for it and didn't find a convenient solution. Any ideas on what I'm missing?

Ayman P.
  • 3
  • 7
  • 1
    Possible duplicate of [How to get the data-id attribute?](http://stackoverflow.com/questions/5309926/how-to-get-the-data-id-attribute) – theoretisch Dec 21 '16 at 11:40

2 Answers2

2

Use attributes in your jQuery selector:

$("div[data-price=price_1][data-capacity=capacity_2][data-debit=debit_2]");
Curtis
  • 101,612
  • 66
  • 270
  • 352
2

You can use the attribute selector for this.

You can do this both with and without jquery.

var elements = document.querySelectorAll('div[data-price="price_1][data-capacity="capacity_1"][data-debit="debit_2"]');

Or with jQuery:

var $elements = $('div[data-price="price_1][data-capacity="capacity_1"][data-debit="debit_2"]');
bigblind
  • 12,539
  • 14
  • 68
  • 123