Reputation: 1926
In jQuery, can I bind a click event to a data
handle instead of a class
? I'm not sure how to word it, but this is what I'm trying to do...
<a data-user="jason">
$(data-user).click(function() { //This is just for example
Right now, I have it this way, but it's causing a lot of problems with other things. Can I use data instead of a class?
<a class="user">
$(".user").click(function() { //This is just for example
Upvotes: 0
Views: 228
Reputation: 57095
$('a[data-user="jason"]').click(function() { .... }
Updated after OP's comment.
$('[data-user]').click(function() { .... }
Upvotes: 4