简体   繁体   中英

Bind click event to Javascript function

I have Jquery latest connected and working with other parts of application.

0. End goal: for a modal window to appear on the screen.

1. I click on a button.

2. A function runs that append a modal to body

3. With modals, in order for this modal to actually show on the screen, I need to press a button that has data-target="#EnterModalNameHere"

4. I make a hidden button in index.html that has the needed data-target property.

5. I would like to be able to click this hidden button once the function in step 2 finishes appending the modal.

How can I tell Javascript "once finished appending modal, click on hidden button"?

You can create an Event.

You can create a custom Event which would be dispatch (trigger) immediately after the document is ready. So, in your situation, since you aren't using a media query, you can use :

  • SetTimeout like setTimeout(() => { do something }, timeout); . So, the timeout could be 1000 - which means 1sec and so on,
  • A custom event which you can trigger when the modal successfully appended to the body.
  • An Event Listeners Like load window.onload = function() { enter code here }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM