DEV Community

Sagar Soni
Sagar Soni

Posted on

Tell me i m right or wrong

     <!-- <!DOCTYPE html>
     <html>
     <body>
         <input id="male" type="radio" value="Male" name="gender"> Male
         <input id="female" type="radio" value="Female" name="gender"> Female

         <button onclick="radio()">Click Me</button>
         <script>
             function radio() {
                 // Using querySelector to find the checked radio button and get its value
                 let selectedGender = document.querySelector('input[name="gender"]:checked').value;
                 alert("You Selected " + selectedGender);
             }
         </script>
     </body>
     </html> -->
1) Does in this code the  querySelector will check input like radio or text or date anything now are radio than code will see name and after checked will check the checked radio and display with the help of alert I m right
Enter fullscreen mode Exit fullscreen mode

Top comments (0)