To change button text using jQuery, the simplest way is to use the jQuery text() method:

$("button").text("Submit");

You can also use the jQuery html() method to change button text.

$("button").html("Submit");

Let’s say I have the following HTML form:

If I want to change the button text inside from “Send” to “Submit”, I can use the jQuery text() method to do this with the following Javascript code.

$("button").text("Submit");

If you are using WordPress, don’t forget to change the $ to jQuery as below:

jQuery("button").text("Submit");

We can also use the jQuery html() method to change the content of the button.

$("button").html("Submit");

While the text() method is very simple, the html() method gives us the ability to insert html into our button, which gives us more options when styling the content. In this case, with buttons, using the html() method probably wouldn’t make sense.

Changing Button Text Using jQuery with a Click

To change button text using jQuery, we can combine the text() method with a click event.

Let’s say I have the following HTML form, and I want to give the user the ability to change the button text from “Send” to “Submit”.


Click here to change button text

We can utilize both the jQuery click() method and jQuery text() method to change the button text from “Send” to “Submit”.

Below is the Javascript code which will allow the user to be able to update the text in the submit button:

$("#click-me").click(function(){
    $("button").text("Submit");
}); 

The final code and output for this example of how to change the text of a submit button using the jQuery text() method and Javascript is below:

Code Output:

Click here to change button text




Full Code:

Click here to change button text
<script> $("#click-me").click(function(){ $("button").text("Submit"); }); </script>

Hopefully this article has been useful for you to understand how to change button text with jQuery.

Categorized in:

jQuery,

Last Update: February 26, 2024