0

I'm working on a page that opens a modal window when the user clicks a certain radio button. I want to trigger whatever that event handler is via my own jQuery code. Right now, I'm attempting to mimic a user clicking on the radio button by:

$("#myRadioButton").trigger("click");

The code works somewhat. The state of the radio button does become selected. However, the modal window does not open.

What must I do to trigger the events and event handlers that make the modal window open?

(Also, is there a way in Chrome DevTools to see what events are attached to an element?)

StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441
  • What are you using for the modal? Some utility frameworks like [Bootstrap](https://getbootstrap.com/docs/4.0/components/modal/#modalshow) have their own custom events and methods for programmatically triggering. – Phil Nov 07 '21 at 22:24
  • I want to be oblivious to how the other event handlers are implemented. I just want to trigger whatever happens when a user clicks on the radio button. – StackOverflowNewbie Nov 07 '21 at 22:40
  • It really depends on how the modal is implemented – Phil Nov 07 '21 at 22:46
  • Does this answer your question? [jQuery $el.trigger('change') doesn't fire native listeners](https://stackoverflow.com/questions/21290775/jquery-el-triggerchange-doesnt-fire-native-listeners) – Phil Nov 07 '21 at 22:54

1 Answers1

-1

This will make the click function work, with a id on the element. You will need to make some logic for the modal itself, inside the function.

Not sure there is a way to see the events in the developer console.

 $( "#myRadioButton" ).click(function() {
    
    //Whatever you wants to happen, when you click the button
     alert( "You clicked on #myRadioButton" );
    });

Try and check out -> https://jquerymodal.com/