0

How can i trigger a click on a radio button if I click on the element click? The element click always comes after the radio button and this should work with multiple radio buttons. Any Idea how this could be done?

<div class="option">
<input type="radio" class="option--input" id="radio1" name="radio">
<div class="click"></div>
</div>

<div class="option">
<input type="radio" class="option--input" id="radio2" name="radio">
<div class="click"></div>
</div>

Here is my try:

$(document).on('click', '.click', function(event) {
    $(this).closest(".option--input").prev().click();
});
1
  • use this context with .prev() or .parent().find() (if multiple radio button) Commented Jul 30, 2016 at 11:04

1 Answer 1

1

There is no need for jQuery at all as there is already a HTML element exactly for this purpose: <label />

.click {
  width: 50px;
  height: 50px;
  background-color: red;
}
<div class="option">
  <input type="radio" class="option--input" id="radio1" name="radio1">
  <label for="radio1">
    <div class="click"></div>
  </label>
</div>

<div class="option">
  <input type="radio" class="option--input" id="radio2" name="radio1">
  <label for="radio2">
    <div class="click"></div>
  </label>
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.