jQuery get an element by its data-id
Similar to this question here, I'm looking to get an element based on it's data-id.
<a href="#" class="whatever" data-item-id="stand-out">...</a>
I'm looking to take action on the a tag. It has a shared class amongst many other elements and has no base id, just a data-item-id.
Can the element be found by it's data-item-id or can I only find out what the data-item-id is?
Solution 1:
$('[data-item-id="stand-out"]')
Solution 2:
You can always use an attribute selector. The selector itself would look something like:
a[data-item-id=stand-out]
Solution 3:
This worked for me, in my case I had a button with a data-id attribute:
$("a").data("item-id");
Fiddle
Solution 4:
Yes, you can find out element by data attribute.
element = $('a[data-item-id="stand-out"]');