jquery method to determine whether radio button radio is selected


This article illustrates how jquery determines whether radio button radio is selected. Share to everybody for everybody reference. The details are as follows:

The html code is as follows:

<input type="radio" id="d1" name="ra" value="a" checked="checked" />
<input type="radio" id="d2" name="ra" value="b" />
<input type="radio" id="d3" name="ra" value="c" />

1. Get id when the page loads

$("input[type='radio']").each(function(){
  var id= $(this).attr("id");
  if($("#"+id).attr("checked")=="checked"){
   var fs=$("#"+id).val();
  }
});
var s1 = $(".aa:checked").val(); // .aa  for class
var s2 = $("input[name='ra']:checked").val();

2. Get id when you click the button

$(function(){
  $("input[type='radio']").click(function(){
    var id= $(this).attr("id");
    alert(id);
  });
});

I hope this article has been helpful for your jQuery programming.