Reputation: 1659
Currently I have a button in which there is no value and I would like to change it when some ajax is called. However my attempts have failed can anyone help as to how I can change and retrieve the value from the button. Below is my code:
<script>
$(document).ready(function() {
$('#favourite').val("4");
});
</script>
<a href="#" id="favourite" data-role="button" data-icon="star" data-iconpos="notext" class="ui-btn-right" value="">mark as favourite</a>
Upvotes: 0
Views: 140
Reputation: 4009
Try this.
$('#favourite').attr('value','4');
Here is a working fiddle.
EDIT
As it was pointed out in the comments by Tolis Emmanouilidis below the 'value' attribute for the anchor tag is invalid. So I would suggest using another data-
attribute instead.
Example.
<a id="favourite" data-value="">CLICK ME</a>
and then to set the value with jQuery.
$('#favourite').on('click',function(){
$(this).data('value','4');
});
and likewise to return the value.
$(this).data('value');
Upvotes: 1