All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Uncheck Radio Button jQuery

Last Updated : Mar 11, 2024

Uncheck Radio Button jQuery

In this article we will show you the solution of uncheck radio button jQuery, here we needs to use attr(), click() and prop() methods for achieve the result.

The attr() and prop() methods almost have same behavior, they purposely used for set or get elements attribute values in jquery.

The click() method triggers the click event, or attaches a function to run when a click event occurs.

Step By Step Guide On Uncheck Radio Button jQuery :-

Here we defined html block with h3 tag for displays heading and button ‘Click Here’, radio type input element ‘Pulser’ with class ‘b’.

In script block we defined ready() method which is automatically starts loading code of within this function when this program opened on browser and within that we sets initial state of input ‘Pulser’ in checked state then we appended click method on button there we changing checked state to ‘false’ for make it as uncheck state by using prop() method.

<!DOCTYPE html>
<html>
    <head>
        <title>Uncheck Radio Button</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
        <script>
            $(document).ready(function (){
                $('.b').attr("checked","checked");
                $('button').click(function(){
                    $('.b').prop("checked",false);
                })
            });
        </script>
        </head>
        <body>
            <h3>Uncheck Radio Button</h3>
                <button>Click Here</button><br><br><br>
                <input type="radio" class="b">Pulser
        </body>
</html>
  1. <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
  2. The<html> tag is used to indicate the beginning of HTML document.
  3. As above shown <head> tag is contain information about webpage and external file links are declared here. <title> tag is used for set the webpage title.
  4. Here we imported open source jquery library support file which is needed for coding using jquery in program.
  5. Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
  6. <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
  7. In script we defined ready() method within that we appending attr() method with class b of radio button for sets it checked state value to ‘checked’ for initially displays in checked state.
  8. Then we defined button with click() method for generate click event when user clicks on ‘Click Here’ button and then we sets radio button ‘Pluser’ class ‘b’ checked state value to ‘false’ by using prop() method which is appended with radio button’s class ‘b’.
  9. In html block we defined h3 tag for showing heading and button, input element with radio button type ‘Pulser’ and class ‘b’.
  10. Both </body>,</html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.

Conclusion :-

In conclusion now we are able to know how to uncheck radio button using jquery.

Before execution of program we needs to confirm internet connection because then only that jquery file will supports defined jquery codes without error.

When we executes program on browser we can see heading ‘Uncheck Radio Button’, button ‘Click Here’ and radio button ‘Pulser’ in checked state now user needs to click on ‘Click Here’ button then radio button goes to unchecked state.

I hope this article on uncheck radio button jQuery helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Ashish

Ashish is a dynamic and motivated individual with a passion of programming and an experienced programmer having 3+ years of experience in various languages like Java, Python, HTML, CSS, JavaScript, jQuery and various frameworks like Bootstrap

Follow Ashish On Linkedin 🡪