I had a similar situation and this worked for me:
$("button").data("item-id");
Similar fiddle, example here
I need to fetch element using "data-id
" attribute of HTML, using jquery, here is the element
<button class="btn btn-primary GetData" data-id="1927" disabled> <i class="fa fa-spinner fa-spin"></i>Get Data</button>
I will remove the .fa-spinner .fa-spin
classes from it, after getting the button using data-id, It has a shared class amongst many other elements and no unique ID.
You can always use an attribute selector, to select element using "data-id" and jquery your code should be
$(button[data-id="122"])
In the above code we are trying to find a button with data-id=122
I had a similar situation and this worked for me:
$("button").data("item-id");
Similar fiddle, example here
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly