jQuery html() change the text of a button

Introduction

Use the jQuery prop() method to change the text of the buttons for HTML <input> element.

To change the <button> element, use the html() method.

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Change Button Text</title>
<script src="https://code.jquery.com/jquery-3.4.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");
});/*  w w w.  ja  v  a 2  s  . c om*/
</script>
</head>
<body>
    <input type="button" id="myInput" value="Input Text">
    <button type="button" id="myButton">Button Text</button>
</body>
</html>



PreviousNext

Related