If I have a link like this:
<a data-btn="login"></a>
If I wished to select in jQuery using the data attribute which should I do?
var a = $("[data-btn='login']"); //This?
var a = $("[data-btn=login]"); //Or this?
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.
As of jQuery 1.5, both approaches will work, and function identically.
jQuery used to require quotes around attribute values, so your second selector won’t work with previous versions. If you’re stuck with an older version for some reason, use the first selector.