How to retrieve button text inside tag button?
Example HTML:
<button type="button" class="btn btn-danger" id="dislikes" value="notThisValue">DISLIKES<span class="glyphicon glyphicon-thumbs-down"></span></button>
My jQuery:
$(document).ready(function(){
$('#dislikes').click(function() {
$("#dislikes").val('Hello World');
})
});
I need to change the text DISLIKES to YOU DISLIKE IT. My jQuery has to change the inner text of the button not the value "notThisValue".
The reason you are not able to change the text is that you are changing its value using .val()
. Instead you need to use .text()
to change tag's text.
Try this.
$(document).ready(function(){
$('#like').click(function() {
$("#like").text('YOU DISLIKE IT');
})
});
Use .text()
or .html()
:
$(document).ready(function() {
$('#dislikes').click(function() {
$(this).text('Hello World');
})
});
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