Possible Duplicate:
Selecting element by data attribute
I'm trying to listen to when an element with a certain data attribute is clicked but I can't seem to get the on click working and I'm sure its something easy on my part that I'm missing. I have
<a href="/home" data-spinner="true" />
$.data('record').click(function() {
//Do Action
});
I have that with variations. My question is, how can I use an data attribute with on click?
Easy solution to your problem: (Not tested)
$('a[data-spinner="true"]').click(function(event) {
});
This selects all elements with the data-spinner attribute, regardless of the value of the attribute.
$( "[data-spinner]" ).live( "click", function () {
console.log('clicked');
} );
The following code binds click
event to all <a>
elements which have data-spinner
attribute equal to true
:
$("a[data-spinner='true']").click(function() {
//Do Acction
});
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