Getting input element value in jQuery

How can I get the value of an input element in jQuery?

+7
jquery html-input forms textinput
source share
5 answers

If this is your textbox :

 <input type="text" id="mytextBox" value="" /> 

You will get its value using the text field ID=mytextBox ...

 var value = $("#mytextBox").val() 

References

+10
source share
 $("#elementId").val() 
+5
source share

The best way is to use the val() function, as in:

 $('#someInput').val(); 

You can also use the attr function to find the value for some fields.

 $('#someInput').attr('value'); 
+3
source share

The val function gets or sets the value of an input field.

Set the input value to "Hello world":

 $('#myInput').val('Hello world'); 

Get input value:

 $('#myInput').val(); 
+3
source share

use jQuery ('inputElement'). val () to get input element (form) values

+2
source share

All Articles