I have a link that is changing some parameters dynamically based on activities on the page. The function for replacing the values seems to be working fine and I can see in the "elements" window in the chrome developer tools that it is being updated. However, when I try to read that value from another JS function, then it is as it has not been changed at all.
I have made a very simplified example of the issue:
<a href="#" id="a-delete-page" data-action="data/1/pageid/0/">
check data-action value</a>
<a href="#" id="toggle">set new value</a>
<script>
$('#a-delete-page').click(test);
$('#toggle').click(toggleValue);
function toggleValue(){
var newValue = '123';
$("#a-delete-page").attr('data-action',newValue);
alert("new value set:"+newValue);
}
function test(){
alert($(this).data('action'));
}
</script>
Try it here: http://jsfiddle.net/2hj3e/
First click "check data-action value" and you see the data-action parameter. Then click set new value (and you see it changes in the developer tool) and click "check data-action value" again. I would expect it to print 123, but it still prints "data/1/pageid/0/".
Could anyone help me understand this and also direct me on how to resolve this.