Getting checked value of element class

Getting checked value of element class

I have tried both of these, but neither works:

  1. var sex = $("input[name=sex]:checked").val();
  2. var sex = $( ".sex option:checked" ).text();

  3. <div style="display:inline;">
  4.         <input type="radio" id="male" class="radio sex" value="male" name="elements[]" checked="checked" />
  5.         <label for="male">Male</label>
  6.         </div>
  7.         <div style="display:inline;">
  8.         <input type="radio" id="female" class="radio sex" value="female" name="elements[]" />
  9.         <label for="female">Female</label>
  10.         <div id="sexMsg" style="margin-top:0px; margin-top:-25px; color:#993300;"></div>
  11.     </div>