0

Triggering a click Event on a Radio Button and a Checkbox results in a slightly different result when you look at the event thta is triggered:

So triggering click on a RadioButton by doing

$('#radio01').trigger('click');

and catching the event on the radio button by

$('#radio01').on('click', reactToClick);

function reactToClick(event) {
    console.log(event);
}

Shows me a different result then doing the same on a checkbox:

$('#myCheckbox').trigger('click');

&

$('#myCheckbox').on('click', reactToClick);

function reactToClick(event) {
    console.log(event);
}

The Checkbox & RadioButton look like this:

<input type="checkbox" id="myCheckbox" name="checkme" />
<label for="myCheckbox">Check Me</label>

<input type="radio" id="radio01" name="radio" value="0" />
<label for="radio01">Option 1</label>

You can see the different output in this Plunkr i created to visualize the problem. Can anyone tell me why it behaves differently?

EDIT: As some answers came already, this is what happens in my browser when i click on those Trigger-Buttons in the Plunkr: enter image description here

5
  • literally, the only difference in your plunkr is the timestamp on the events. Commented Jul 10, 2017 at 13:17
  • The console might show a different excerpt, but the objects are probably for all intents and purposes the same Commented Jul 10, 2017 at 13:17
  • For the checkbox the only difference is the "isTrusted": false, with .trigger() instead of true, and it's quite logical because the event is triggered with a script which can be a security problem. Commented Jul 10, 2017 at 13:19
  • And triggering a radioButton with a script is not a security problem? Commented Jul 10, 2017 at 13:23
  • 1
    jsfiddle.net/adeneo/ury6hs8a Commented Jul 10, 2017 at 13:32

0

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.