I have the following HTML
<div class="element" data-settings={"apples":1,"bananas":4,"speed":300}>
</div>
The values in data-settings
can be changed in my app however the js code that updates the values is written in Reactjs, is minified and unreadable. I just want to get some values using simple jquery in my own js.
In my own js, when I click .element
I want to get the updated value of data-settings
.
My code:
$('.element').on('click', function() {
console.log( $(".element").data("settings") );
});
It returns the data-settings
values but when I update a setting and click .element
again it does not return the updated values.
For example, I update apples
to 8 in my app. I see data-settings={"apples":8,"bananas":4,"speed":300}
in the HTML but in my console log, apples are still 1.
I also tried:
$('body').on('click', '.element', function() {
console.log( $(".element").data("settings") );
});
and does not work.
How can I see the live changes to the data attribute settings
in my js?