TutanRamon
TutanRamon

Reputation: 215

Jquery: Uncheck a radiobutton (in a group of 1 radiobutton)

I have this code to uncheck a group of radiobuttons:

$('form[id^="fm-form"]')
     .find("input.groupOfButtons:radio:checked")
     .prop('checked',false);

This works fine when there are at least two radiobuttons in the group.

If there is only one, the script doesn't work.

How can I disable a radiobutton when there is only 1 radiobutton?

Upvotes: 0

Views: 1311

Answers (2)

Hearaman
Hearaman

Reputation: 8736

Check this program, It is working for me

        <html>
            <head>
                <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
                <script type="text/javascript">
                    $(document).ready(function()
                    {
                        $("#Check").click(function()
                        {                    
                            $("#radio").prop('checked', true);
                        });

                        $("#UnCheck").click(function()
                        {                    
                            $("#radio").prop('checked', false);
                        });
                    });
                </script>
            </head>
            <body>
                <input type="radio" id="radio" />
                <button id="Check">Check</button>
                <button id="UnCheck">Un Check</button>
            </body>
        </html>

Upvotes: 2

coolxeo
coolxeo

Reputation: 563

Try to use removeProp instead of prop

.removeProp('checked')

Upvotes: 1

Related Questions