Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  55] [ 2]  / answers: 1 / hits: 34394  / 12 Years ago, wed, october 17, 2012, 12:00:00

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.


More From » jquery

 Answers
16

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/


[#82501] Tuesday, October 16, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alejandro

Total Points: 231
Total Questions: 102
Total Answers: 107

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
alejandro questions
Mon, Jul 18, 22, 00:00, 2 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
Thu, Sep 10, 20, 00:00, 4 Years ago
;