Learn jQuery

jQuery val()

jQuery val() is used to get the value of first matched element or sets the value for each matched element.

Syntax

jQuery.(selector).val() // Return the val for the matched elements jQuery.(selector).val(value); // Set the val for the matched elements

Example

HTML
<!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())
});
});