Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to create dynamic radio button in jquery

<!DOCTYPE html>
<head>
    <title>
        How to check a radio
        button with jQuery?
    </title>
      
    <script src=
        "https://code.jquery.com/jquery-2.2.4.min.js">
    </script>
</head>
  
<body>
    <h1 style="color: green">
        GeeksForGeeks
    </h1>
    <b>jQuery Check/Uncheck Radio Button</b>
    <p>
        <input type="radio" name="option" id="free">
            Free Membership
        <input type="radio" name="option" id="premium">
            Premium Membership
    </p>
      
    <p>
        <button type="button" class="check-free">
            Get Free
        </button>
          
        <button type="button" class="check-premium">
            Get Premium
        </button>
          
        <button type="button" class="reset">
            Reset options
        </button>
    </p>
      
    <script type="text/javascript">
        $(document).ready(function () {
            $(".check-free").click(function () {
                $("#free").attr("checked", true).click();
            });
            $(".check-premium").click(function () {
                $("#premium").attr("checked", true).click();
            });
            $(".reset").click(function () {
                $("#free").attr("checked", false);
                $("#premium").attr("checked", false);
            });
        });
    </script>
</body>
  
</html>
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #create #dynamic #radio #button #jquery
ADD COMMENT
Topic
Name
7+1 =