I have a page where you can search for customers through an ajax search. In the ajax file it chucks all the results from mysql with html into a php var and passes it to JS which sticks it in a div. This part works fine.
Before the ajax was put in, I used a standard html form/php/mysql search. On each row (and still) there is a button to open a modal which is coded below.
<button class="button smsModal" id="patient301" fullname="Nathan Ironsi" phone="61425819959"><i class="fa fa-mobile"></i> sms</button>
Now that I am using content generated from the ajax call, this button has stopped working. I have checked the html and I have it formatted the same way as before, but the javascript is not picking up the clicks.
Could someone please explain what mistake I have made? My guess is JS doesn't like pulling html that was not a part of the original page html, but I do not know how to go about fixing this (or if it is indeed possible!)
Modal script:
$(".smsModal").on('click', function(){
$.Dialog({
overlay: true,
shadow: true,
flat: true,
draggable: false,
icon: '',
title: 'SMS',
content: '',
padding: 24,
onShow: function(_dialog){
var getIdFromButton = $(event.target).attr('id');
var getFullName = $(event.target).attr('fullname');
var getPhone = $(event.target).attr('phone');
var content = 'CONTENT GOES HERE';
$.Dialog.title("Send SMS to " + getPhone);
$.Dialog.content(content);
}
});
});
Thank you!
$(".smsModal").on('click', function(){to$(document.body).on('click', 'button', function(){. Yay!