How to Intercept click on a button in pure JavaScript?

The code has to intercept the click on the button. And not let the other event occur, just the event below. Thank you : )

document.addEventListener("DOMContentLoaded", function(event) { 
if (confirm("Are you sure you want to delete the message?")){

Can you please give further details about which event is the other event that you don’t want to occur?

And the “delete the message” event, I think it is jquery ajax. I am placing a confirm button before it. It is very easy to delete.

The mutation observer can be used to watch for changes to an element and defer an action like a button click until a specific element becomes part of the dom. Otherwise you could use a legacy method of polling – waiting a certain period of time to check for the element on repeat until it exists.

Resolved, thank you very much for your comments. No need anymore, send me messages.

The thread will remain here so that everyone that comes along afterwards may benefit from what was done.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.