Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the text of a submit button using JQuery?

For some reason $("#thebutton").val("New text") doesn't work.

like image 507
TIMEX Avatar asked Feb 19 '10 08:02

TIMEX


2 Answers

Well, this works for me (tested on Chrome 4, FireFox 3.6, IE8):

<html>
<head>
    <title>Test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(function() {
        $("#thebutton").val("New text");
    });
    </script>
</head>
<body>
    <input id="thebutton" type="submit" value="OK" />
</body>
</html>
like image 121
Darin Dimitrov Avatar answered Oct 05 '22 12:10

Darin Dimitrov


If you are using html button i.e. <button id='thebutton ' > Button Val </button> then use $("#thebutton").text("NEW Text");

like image 39
Tepu Avatar answered Oct 05 '22 11:10

Tepu