Checking every radio button
Hey guys I am knew to jQuery and I'm not completely sure if i am using the syntax correctly. I would like every radio button to be selected when I click the on the button. If someone could guide me some where or explain what is wrong with my code much would be appreciated. Thank you.
- <!DOCTYPE HTML>
- <html>
- <head>
- <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
- <style>
- </style>
- <script>
- $("input:radio").each(function() {
- if ($(this).attr('checked') != "checked"){
- $(this).attr("checked","checked");
- });
- </script>
- </head>
- <body>
- <form>
- <input type="radio" value="male">Male<br>
- <input type="radio" value="female">Female
- </form>
- <form>
- <input type="radio" value="male">Male<br>
- <input type="radio" value="female">Female
- </form>
- <form>
- <input type="radio" value="male">Male<br>
- <input type="radio" value="female">Female
- </form>
- <form>
- <input type="radio" value="male">Male<br>
- <input type="radio" value="female">Female
- </form>
- </body>
- </html>