jQuery val() is used to get the value of first matched element or sets the value for each matched element.
jQuery.(selector).val() // Return the val for the matched elements
jQuery.(selector).val(value); // Set the val for the matched elements
<!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script> <title>jQuery val() Example </title> </head> <input type="text" name="textBox" id="textBox" value="My Text"> <input type="button" value="Press Me" id="pressMe"> <div></div> </html>Javascript
$(document).ready(function(){ $("#pressMe").click(function () { alert($("#textBox").val()) }); });