The jQuery :text Selector is used to select input element with having a text field i.e (type==text).Â
Syntax:Â
$(":text") Example 1: In this example, we will select the input element that has a text field by using jQuery :text Selector.
<html>
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
script>
<script>
$(document).ready(function () {
$(":text").css("background-color",
"green");
});
script>
head>
<body>
<center>
<h1 style="color:green;">
GeeksForGeeks
h1>
<h2>jQuery :text Selectorh2>
<form action="">
Name:
<input type="text" name="user">
<br>
Password:
<input type="password" name="password">
<br>
<br>
<input type="reset" value="Reset">
<input type="submit" value="Submit">
<br>
form>
center>
body>
html>
Output:
Â
Â
Example 2: In this example, we will change the background color of the input element that has a text field with the help of click function.
<html>
<head>
<script src=
"https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
script>
<script>
$(document).ready(function () {
$("button").click(function () {
$(":text").css("background-color",
"yellow");
});
});
script>
head>
<body>
<center>
<h1 style="color:green;">
GeeksForGeeks
h1>
<h2>jQuery :text Selectorh2>
<form action="">
Name:
<input style="background-color: aqua;"
type="text" name="user">
<br>
Password:
<input style="background-color: blueviolet;"
type="password" name="password">
<br>
<br>
<input type="reset" value="Reset">
<input type="submit" value="Submit">
<br>
<button>change colorbutton>
form>
center>
body>
html>
Output:
