Is it possible to select a hidden radio button
in Using jQuery
•
13 years ago
Ran into an issue today I wasn't able to sort out on my own or through a Google search:
I have this form where I wanted to select a radio button when the containing div was clicked. So, on the click of the div, I would say that the radio's attribute of checked was set to checked.
It all worked fine until I put on the document.ready to hide all the radios.
Thus, with a hidden radio input, I was unable to manipulate the checked attribute. Did I miss something? Example code for reference:
- $(document).ready(function(){
- $("input[type=radio]").hide();
- $("form div").click(function(){
- $(this).find("input[type=radio]").attr("checked","checked");
- $("form").submit();
- });
- });
So to re-iterate, if I didn't have that initial hide in there, it'd work. Also, if I did
- ...
- $(this).find("input[type=radio]").show().attr("checked","checked");
- ...
It also worked. So, I wanted to clear up what I may have missed as to why it didn't work. Thanks!
1