Jquery - find which radio was checked and trigger a click for the sibling

i have a simple markup, where i would like to loop thro checkboxes states and see which one was checked upon which the final trigger button outside the form triggers a click for the sibling button of the checked input when clicked. Any help to get me started appreciated. My markup: JsFiddle

Answers 1

  • $('#finalbutton').on('click', function(w) {
    
      $('input:radio:checked').siblings('button').click(); //get the sibling button and click it manually
    
        w.preventDefault();
    });
    
    $('div button').on('click', function(w) {
    
      console.log($(this).text())
    });
    

    demo

    I added a prevent default to avoid the from submitting(for checking only) check the console for the button that is triggered. I also added an ID for the final button.


Related Articles