jQuery Examples - $(":input")
Description
"$(":input")" Selects only form elements (input, select, textarea, button).
Syntax
Here is the simple syntax to use this selector −
$(":input")
Parameters
Here is the description of all the parameters used by this selector −
:input − form elements selector
Returns
This selector returns an array filled with the input elements.
Example
<html>
<head>
<title>The Selector Example</title>
<script type = "text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script type = "text/javascript" language = "javascript">
$(document).ready(function() {
/* Selects the visible <li> element..*/
$(":input").wrap( "<span></span>" ).parent().css("background-color", "yellow");
$(":input").val("Enter Name.");
});
</script>
</head>
<body>
<p>Highlighted Form elements</p>
<form>
<table>
<tr><td>Name</td><td><input type = "text"></td></tr>
<tr><td>Password</td><td><input type = "password"></td></tr>
<tr><td>Gender</td>
<td><input type = "radio" name = "gender" value = "male">Male<br/>
<input type = "radio" name = "gender" value = "female">Female</td>
</tr>
<tr><td>Food</td>
<td><input type = "checkbox" name = "chinese" value = "chinese" checked>Chinese<br/>
<input type = "checkbox" name = "indian" value = "indian">Indian</td>
</tr>
</table>
</form>
</body>
</html>
This will produce following result −
jqueryexamples_selectors.htm
Advertisements