[javascript] 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?

This question is related to javascript jquery

The answer is


$('[data-item-id="stand-out"]')


Yes, you can find out element by data attribute.

element = $('a[data-item-id="stand-out"]');

This worked for me, in my case I had a button with a data-id attribute:

$("a").data("item-id");

Fiddle