Form Radio button (input:radio)

Description and Syntax

$(":radio")

selects all radio button fields (<input type="radio">).

Examples

The following code counts the radio button element for a form.


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){<!-- w  w  w.j a  v  a 2  s  .c o  m-->
            alert($(":radio").length);
        });
    </script>
  </head>
  <body>
    <body>
    <form>
        <input type="button" value="Input Button"/>
    
        <input type="checkbox">java2s.com</input>
        <input type="checkbox" />
        <input type="checkbox" />
        <input type="file" />
        <input type="hidden" />
        <input type="image" />
        <input type="password" />
        <input type="radio" />
        <input type="reset" />
        <input type="submit" />
        <input type="text" />
    
        <select><option>Option<option/></select>
        <textarea></textarea>
        <button>Button</button>
    </form>    
    </body>
</html>

Click to view the demo

The code above generates the following result.

Form Radio button (input:radio)

Find radio button within the first form

Finds all inputs of type radio within the first form in the document


<html>
  <head>
    <script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
       $(document).ready(function(){<!--   w  ww .  j av  a  2s  .c o  m-->
         alert($("input:radio", document.forms[0]).length);
       });
    </script>
  </head>
  <body>
   <form>
      <input type="radio" value="Option">
   </form>

  </body>
</html>

Click to view the demo

The code above generates the following result.

Form Radio button (input:radio)