I do not find any example how to read unobtrusive data using jQuery. For example below
<a id="deleteFile" href="" data="123">Delete file</a>
I would like to read data attribute from a element. How to do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The best way is to just get the element attribute
If your using a newish jquery library version (higher than 1.6 i belive) you can also use HTML5 data attributes with jQuery’s
data(). Change your anchor link to something likethen you can use
However do NOT use them interchangeably, use one method only otherwise you may incur issues later on as jQuerys
data()will only READ the data attributes then store them in an internal cache. If you change anything viadata(), it will not be changed in the actual tag attribute meaningdata()andattr()will return different results thereafter