JQuery Selector radio

From CoderLearner
Jump to: navigation, search

Description

Select element that it has the type radio.

Syntax

$('input:radio')

$('form input:radio')

$('input[type="radio"]')

Note

For better performance use $('input[type="radio"]')

Example 1

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Select</title>
      <script 
         type="text/javascript" 
         src="/lib/jquery-1.7.2.min.js">				 
      </script>

      <script>
         $().ready(function() {
            var sizz=$('input[name="car0"]:radio').length;
            $('span').html(sizz);
            
            $('input:radio').parent().css('background-color','yellow');
         });
      </script>
   </head>
   <body> 
      <span></span>
      <form>
         <input type="radio" name="car0"/>
         <input type="radio" name="car0"/>
         <input type="radio" name="car0"/>
         <input type="radio" name="car0"/>
      </form>
   </body>
</html>

Try It

Assign Check or uncheck radio button


<input type="radio" id="soemthing"/>

$('#soemthing').attr('checked',true); // make check
$('#soemthing').attr('checked',false); // make uncheck