I am trying to update the text of a button when it is clicked. I have a number of buttons with the same class but no id. Why doesn't this work?
<input type="button" class="add-button" value="Default" />
<input type="button" class="add-button" value="Default" />
<input type="button" class="add-button" value="Default" />
<input type="button" class="add-button" value="Default" />
$(document).ready(function() {
$('.add-button').click(function() {
alert('clicked');
$(this).html('Changed');
});
});
The alert is triggered, but the button isn't changed.
Use this.value for input. See below,
$(document).ready(function() {
$('.add-button').click(function() {
alert('clicked');
this.value = 'Changed';
});
});
DEMO: http://jsfiddle.net/qU5tR/10/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With