Checked Selector in jQuery?

This is an advanced selector in jQuery. This selector is often used to identify the input type it supports all types of input like checkbox, radio button, etc. Let’s see an example to understand more clearly.

Step 1 create a simple HTML page which have input fields. Here, we create a test.html file.
<html>
<head>
  <meta charset="utf-8">
  <title>Program to check input</title>
  <style>
  div {
    color: orange;
  }
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
 
<form>
  <div>
    <input type="radio" name="fruits" value="red" id="red">
    <label for="orange">orange</label>
  </div>
  <div>
    <input type="radio" name="fruit" value="green" id="green">
    <label for="apple">apple</label>
  </div>
  <div>
    <input type="radio" name="fruit" value="blue" id="blue">
    <label for="banana">banana</label>
  </div>
  <div id="result"></div>
</form>
 
<script>
$( "input" ).on( "click", function() {
  $( "#result" ).html( $( "input:checked" ).val() + " is checked!" );
});
</script>
 
</body>
</html>
In the above code we after create .html file, we have included script which perform the task. Output :-
In the above output we have select apple so output is apple is checked.