I have a link and when is pressed the value of the text and data attribute of one div is changing. I have another link when is pressed i get those changed values. Here is the code:
<a class="first" href="#">change value</a>
<a class="second" href="#">get value</a>
<div class="value" data-test="test">test</div>
$(document).ready(function() {
$('.first').on('click', function(e) {
e.preventDefault();
$('.value').html($(this).text()).attr('data-test',$(this).text());
});
$('.second').on('click', function(e) {
e.preventDefault();
$value = $('.value').text();
$data = $('.value').data('test');
alert($data);
});
});
http://jsfiddle.net/4daoqzc8/2/
The problem is that after value are changed i can get the new text value of the div but the value of the data attribute remains the same as was when the dom loaded. How can i get the new value of the data attribute?