Form Selectors
$(":input")
$(":text")
$(":checkbox")
$(":radio")
$(":submit")
Input Selector
':input' page पर हर form control को match करता है, सिर्फ <input> tags नहीं बल्कि textareas, selects, और buttons भी शामिल करते हुए। यह jQuery के form-related selectors में सबसे broad है।
उदाहरण: Input Selector
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
</head>
<body>
<input><textarea></textarea><button>Go</button>
<script>
console.log($(":input").length);
</script>
</body>
</html>
Text Input Selector
':text' selector इसे सिर्फ single-line text inputs तक narrow कर देता है, checkboxes या buttons जैसी हर दूसरी control type को नज़रअंदाज़ करते हुए। यह input[type="text"] का shorthand है लेकिन थोड़ा धीमा है क्योंकि यह एक native browser lookup इस्तेमाल नहीं कर सकता।
उदाहरण: Text Input Selector
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
</head>
<body>
<input type="text"><input type="checkbox">
<script>
console.log($(":text").length);
</script>
</body>
</html>
Password Selector
':password' selector सिर्फ password fields को target करता है, जो तब उपयोगी है जब आपको उस specific input को regular text fields से अलग तरीके से validate या mask करना हो।
उदाहरण: Password Selector
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
</head>
<body>
<input type="password"><input type="text">
<script>
console.log($(":password").length);
</script>
</body>
</html>
Checkbox और Radio
':checkbox' और ':radio' आपको उन specific control types को सीधे select करने देते हैं, जो अक्सर यह पढ़ने या set करने के लिए .prop(checked) के साथ जोड़े जाते हैं कि वे इस समय selected हैं या नहीं।
उदाहरण: Checkbox and Radio
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
</head>
<body>
<input type="checkbox" checked><input type="radio">
<script>
console.log($(":checkbox").prop("checked"));
</script>
</body>
</html>
Submit और File
jQuery submit buttons के लिए ':submit' और file-upload inputs के लिए ':file' भी provide करता है, form-control selectors के पूरे set को complete करते हुए जिन्हें आप individually target कर सकते हैं।
उदाहरण: Submit and File
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
</head>
<body>
<input type="submit"><input type="file">
<script>
console.log($(":submit").length, $(":file").length);
</script>
</body>
</html>
- यह मान लेना कि
:inputसिर्फ<input>tags match करता है; यह<textarea>,<select>और<button>को भी match करता है। :textइस्तेमाल करना और उम्मीद करना कि यह किसी<textarea>या बिनाtypeattribute वाले input को reliably ढूँढ लेगा, जबकि यह सिर्फinput[type=text]को target करता है।$(":checkbox")लिखना और सिर्फ checked boxes की उम्मीद करना; यह हर checkbox select करता है, और narrow करने के लिए आपको:checkedचाहिए।
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: