Hector Landete
Hector Landete

Reputation: 367

Run jquery inside sweet alert

I have some rows where the user can click and then I run a jQuery function, everything working fine.

As some rows have extra options I decided to load those extra options in a popup window using sweet alert and they should do the same (when the row inside the sweet alert is clicked run same function)

The problem is that the rows inside the sweet alert popup are not calling any function on click. Why can be this?

Can I use sweet alert for this or should I look for other plugin?

This is how I'm calling the jQuery function

$('.maincontent').on('click', '.betHandle', function () {
    add(this);
});

Upvotes: 1

Views: 452

Answers (1)

Adam
Adam

Reputation: 3288

I think there is one of two possible reasons it isn't working.

  1. as @sweaver2112 has suggested, your .betHandle may not be under .maincontent in the DOM tree
  2. you're adding the listener before .maincontent is added to the DOM

In either case, adding the listener to the body will work:

$('body').on('click', '.betHandle', function () {
   add(this);
});

Upvotes: 1

Related Questions