jQuery :password Selector
The jQuery :password Selector is used to select the input element having password field . i.e (type==password)
Syntax:
$(":password")
Example 1: In this example, we will select the input element which has a password field by using jQuery :password Selector.
HTML
<!DOCTYPE html> < html > < head > < script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" > </ script > < script > $(document).ready(function () { $(":password").css("background-color", "green"); }); </ script > </ head > < body > < center > < h1 style = "color:green;" > w3wiki </ h1 > < h2 >jQuery :password Selector</ h2 > < 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 which has a password field with click function.
HTML
<!DOCTYPE html> < 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 () { $(":password").css("border", "2px solid red"); }); }); </ script > </ head > < body > < center > < h1 style = "color:green;" > w3wiki </ h1 > < h2 >jQuery :password Selector</ h2 > < 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 > < br > < button >Add border</ button > </ form > </ center > </ body > </ html > |
Output:
Contact Us