Reputation:
I have the following code:
$('#loginLink, #registerLink')
.attr('data-disabled') === 'yes'
I am trying to set the data-disabled attribute on the IDs but it does not seem to work. Am I using the correct jQuery?
Upvotes: 5
Views: 4327
Reputation: 58595
You set the value of an attribute like this:
$('#loginLink, #registerLink').attr('data-disabled','yes');
To retrieve a value stored like this, you can either:
$('yourselector').attr('data-disabled');
or
$('yourselector').data('disabled');
Upvotes: 4
Reputation: 1918
$('#loginLink, #registerLink').attr('data-disabled','yes')
maybe? I am not familiar with that attribute, but this is how they are usually attributed.
Upvotes: 0
Reputation: 1449
Generally in jQuery, any attribute should be set as below:
$(<selector>).attr("<attr name>", "<attr value>");
Hope this Helps!!
Upvotes: 1
Reputation: 144669
You should set the value this way:
$('#loginLink, #registerLink').attr('data-disabled', 'yes');
As data is a property, you can use data
method instead:
$('#loginLink, #registerLink').data('disabled', 'yes');
Upvotes: 11