0

I have the following HTML:

<div id="Root">
    <div class="sub">
        <button data-help-id="104" class="btn btn-primary">Select 1</button>
        <button data-help-id="122" class="btn btn-default">Select 2</button>
    </div>
</div>

I would like to select all the elements that have the jQuery data key "help-id" (data-help-id in the element markup). This is irregardless of the value of the attribute.

This data attribute may be applied to many different elements - div's, span's, etc, so merely selecting the buttons will not work. I do not want to go to the additional effort of adding a specific class name to these elements either.

I did see this post: Find all elements that have a certain data attribute (regardless of value) - however, I am not selecting a group of elements which to filter on first. I wanted this to be as lightweight as possible - and simply have the selector run on page load so that it can do the DOM manipulation.

Is this possible?

Community
  • 1
  • 1
Barry Chapman
  • 6,690
  • 3
  • 36
  • 64
  • 1
    Use `$('[data-help-id]')`. – Tushar Jun 12 '16 at 13:59
  • Except that the question you referenced is not the same as the question I was asking at all. That one selects attributes by a KVP, not just by the key - which is what I am looking for. – Barry Chapman Jun 12 '16 at 13:59
  • always go to the **Mecca** of selectors http://www.w3schools.com/cssref/css_selectors.asp your question is answered on the `10th` line, `[attribute]` – warkentien2 Jun 12 '16 at 15:30

0 Answers0