Q:

How to Change the Text of a Button using jQuery

0

How to Change the Text of a Button using jQuery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the jQuery prop() and html() Methods

You can simply use the jQuery prop() method to change the text of the buttons built using the HTML <input> element, whereas to change the text of the buttons which are created using the <button> element you can use the html() method.

The jQuery code in the following example will change the button text on document ready:

<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Change Button Text</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function(){
    // Change text of input button
    $("#myInput").prop("value", "Input New Text");
    
    // Change text of button element
    $("#myButton").html("Button New Text");
});
</script>
</head>
<body>
    <input type="button" id="myInput" value="Input Text">
    <button type="button" id="myButton">Button Text</button>
</body>
</html>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Loop Through Elements with the Same Class i... >>
<< How to Set the Value of Input Text Box using jQuer...