How to get an element by its data-id using jquery?

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.

Asked by:- pika
: 3439 At:- 8/22/2017 4:02:06 PM
javascript jQuery get-element-using-data-id

2 Answers
profileImage Answered by:- Vipin

You can always use an attribute selector, to select element using "data-id" and jquery your code should be


In the above code we are trying to find a button with data-id=122

At:- 8/23/2017 3:55:42 PM Updated at:- 8/23/2017 3:56:37 PM
thanks for the above answer, it helped me 0
By : pika - at :- 8/31/2017 11:17:06 AM

profileImage Answered by:- vikas_jk

I had a similar situation and this worked for me:


Similar fiddle, example here 


At:- 8/23/2017 3:58:14 PM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use