There is:

<form id="formtabs" name="formtabs"> <div><input type="radio" name="nametab" id="nametab" value="lastmaterials" /> <h3>Материалы</h3></div> <div><input type="radio" name="nametab" id="nametab" value="lastphotos" /> <h3>Фотографии</h3></div> <div><input type="radio" name="nametab" id="nametab" value="lastwork" /> <h3>Портфолио</h3></div> </form> 

I want to click on the #formtabs div to change the checked value in the input: radio, which is inside it.

There is such an option, but it does not work:

 $('#formtabs div').click(function(){ $('this').has('input').val('checked','checked'); }); 

    3 answers 3

    Well, first, the id-thing is unique to the DOM. So replace the "nametab".
    Secondly, the radio switch only 1 item can make selected. Do you want the next one to be selected when clicking?

    • No, I want to click on the div, and the element that was inside it was selected, clicked on the next div, removed from the last checked, and got up on it. Primitive like a problem, but I do not know how to get to the child diva. - chuikoff
    • $ (this) .children ('input') Found that he is gaining access so, but for some reason it is not checked - chuikoff
    • Problem solved! - chuikoff

    Replace the div with a label and remove javascript.

      Yes, right. The has () filter selects not an embedded element (in your case a switch), but the element containing it. This filter selects all divs that contain input. Therefore, it did not work: for the div that contains the switch cannot be set to the value of checked. But this is impossible?

       $('#formtabs div').click(function(){ $(this).find('input').attr('checked', checked); }); 

      Or use val () to change the state of the switch.