1
In jQuery, it is possible to define values for an attribute through the data
.
Thus:
$('body').data({id: 1, nome: 'stack'});
And the result of that would be:
console.log($('body').data()); // {id: 1, nome: 'stack'}
But if I want to rewrite the object, I can’t do it with data
.
$('body').data({nome: 'stack'});
console.log($('body').data()); // {id:1, nome: 'stack'}
Note that the id
continued there, even though I reset the value of the date.
How can I erase a value from data
or the whole value of data
in jQuery?
you can undo the id:
$('body').data.id = null;
– Ivan Ferrer
How can you remove:
delete $('body').data.id;
– Ivan Ferrer
As can also remove using the function
removeData()
jQuery:$('body').data.removeData('id');
– Ivan Ferrer