javascriptjqueryhtmlalertalertify

Assign event to button from external library


Every time I press a button, there is a random chance that a alertify alert window popups. The alertify alert popup is something I use instead of javascript Alert, just to get a nicer design.

Alertify library

And here is a screenshot of the current situation:

enter image description here

I want to assign a event to the OK button. When I use the "inspect element" function in google chrome, I see that this green OK button has an id called "alertify-ok", so I want to assign an event when this button is pressed.

I've tried to add this part to my HTML document in the script part:

$( "#alertify-ok" ).on( "click",function() {alert("finally");});

But nothing happens. The reason why I need this to work, is that the youtube popupmodal should come up right after I've pressed the OK button. I belive the error comes because the alertify window with HTML is from an external library, so how can i do this?


Solution

  • Alerts and the others take callback functions on creation, https://github.com/alertifyjs/alertify.js/blob/0.3.12/src/js/alertify.js#L608. You don't need to attach another event listener, just give it the function you want it to execute. example below:

    alertify.alert("alerttext", function(e) {
        functionIWantToCall();
    });