Home
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"> </script> <script> $(document).ready(function () { $('#btnSubVal').click(function(){ alert($('input:Submit').val()); //display value of button }); $('#btnTxtVal').click(function(){ alert($('input:text').val()); //display value of textbox }); //set value of textbox to "Steve" $('input:text').val('Steve'); }); </script> <style> div{ margin:10px 0 0 0; } </style> </head> <body> <h1>Demo: jQuery val() method</h1> <button id="btnSubVal">Get button value</button> <button id="btnTxtVal">Get textbox value</button> <div> <label>Name:</label><input type="text"/> </div> <div> <input type="submit" value="Save" /> </div> </body> </html>
Result: