Search code examples
jqueryradio-button

.is(':checked') not working in jquery


Hello friends I want when user checked the radio box then the text will show following is my code you can also check my code here http://jsfiddle.net/mY4N5/

HTML

<form id="form1" name="form1" method="post" action="">
  <label>
  <input name="radiobutton" type="radio" value="radiobutton" id="red"/>
  </label>
</form>
<div id="dis">
hi

</div>

Script

$('#dis').css('display','none');

    if($('#red').is(':checked'))
    {
    $('#dis').css('display','block');
    }
    else
    {
        $('#dis').css('display','none');
    };

Solution

  • If you use radiobutton and the value of specific radio is important you can use this
    http://jsfiddle.net/LcEn6/
    If you want just have one of them checked and no mater what which one you can use this.
    http://jsfiddle.net/V4W7j/