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?
To get the name, you'd use $(selector). attr('name') which would return (in your example) 'xxxxx' . Save this answer.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With