In this blog, we will learn about how to use :checked selector to html elements. This selector is used to select all checked checkboxes, radio buttons, and options of select elements. The below example shows the checked checkboxes.
Syntax:
$(":checked")
Follow the below snippet to learn about :checked selector in jQuery.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Jquery :checked selector</title>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
$(document).ready(function(){
$(":checked").wrap("<span style='background-color:#ff0000'>");
});
</script>
<style>
.form-style {
padding:50px;
text-align: left;
}
form {
font-weight: bold;
font-size: 25px;
color: #4000ff;
}
</style>
</head>
<body>
<div class="form-style">
<form action="">
Name: <input type="text" name="user"><br>
Ticket 1: <input type="checkbox" name="ticket" value="ticket1"><br>
Ticket 2: <input type="checkbox" name="ticket" value="ticket2"><br>
Ticket 3: <input type="checkbox" name="ticket" value="ticket3" checked="checked"><br>
<input type="submit">
</form>
</div>
</body>
</html>
Popular Posts
- Show / Hide div based on dropdown selected using jQuery
- Autosuggestion Select Box using HTML5 Datalist, PHP and MySQL with Example
- Infinite Scrolling on PHP website using jQuery and Ajax with example
- How to Convert MySQL Data to JSON using PHP
- Custom Authentication Login And Registration Using Laravel 8
- Image Lazy loading Using Slick Slider
- Slick Slider Basic With Example
- Google Login or Sign In with Angular Application
- How to change date format in PHP?
- php in_array check for multiple values
- Adaptive Height In Slick Slider
- Slick Slider Center Mode With Example
- How to Scroll to an Element with Vue 3 and ?
- JavaScript Multiple File Upload Progress Bar Using Ajax With PHP
- Slick Slider Multiple Items With Example
Total Views: 92