Home > other >  Button onlick show alert box
Button onlick show alert box

Time:02-11

I have a modal and after pressing the password update button, the modal should close and an alert box should appear on my homepage. however, the alert box will not appear when the page is first opened. how can I do it? Do you have any examples you can share?

CodePudding user response:

If you are using the alerts provided by the browser, you have to add a EventListener to your button like:

yourCloseButton.addEventListener("click", () => {
  alert("The modal has been closed!");
});

CodePudding user response:

Complementing Apollo79's answer, you can also use an inline event listener, but this is no longer recommended. There are some specific cases for this, but if you really don't need one, use Apollo79's answer instead.

<button id="urButton" onclick="alertAndDisappear()">

or

yourCloseButton.onclick = function(){}

which is equivalent to the first one.

Again, only use these if you really need them

  • Related