Reputation: 93
I have a div like this:
<div id="something" data-tip="tipeofdata"></div>
Then I want to change that data-tip with Jquery. I was trying like this:
$('#something').data('tip') = 'newdata';
But doesnt work. How can I do this?
Thanks.
Upvotes: 0
Views: 49
Reputation: 13511
Try the following. This is what I am using and it works fine:
$('#something').attr('data-tip', 'newdata');
But also you can try the following:
$('#something').data('tip', 'newdata');
I have not tried that, but I suppose will work.
Upvotes: 0
Reputation: 74420
Wrong syntax:
$('#something').data('tip') = 'newdata';
Should be:
$('#something').data('tip','newdata');
But that will change data object property value, not DOM node attribute
To change attribute on DOM node, you need to use:
$('#something').attr('data-tip','newdata');
Upvotes: 1