I have the following modal:
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 id="mt" class="modal-title" id="myModalLabel"></h4>
</div>
<div id="mb" class="modal-body">
</div>
<div id="mf" class="modal-footer">
</div>
</div>
</div>
I have a button in a table, which kicks off a jquery ajax call and pulls in the title, body, and footer of the modal. You can see that script below.
<script>
$(document).ready(function(){
$('a.btn').click(function(){
var org_id = $(this).attr('org_id');
$.ajax({
type: 'post',
url: '/groups/' + org_id + '/leave',
success: function(data){
var data = $('<div>').html(data);
var msg1 = data.find('#msg1');
var msg2 = data.find('#msg2');
var msg3 = data.find('#msg3');
$('#mf').html(msg3);
$('#mt').html(msg2);
$('#mb').html(msg1);
}
});
});
$('#killgroup').click(function(){
alert('made it');
});
});
</script>
Once the modal is fully populated with data, the footer section looks like this:
<div id="mf" class="modal-footer"><div id="msg3"><a id="killgroup" class="btn btn-danger">I'm Positive. Kill Group Forever.</a><a data-dismiss="modal" class="btn btn-success">Wait! Let me re-think this.</a></div></div>
The problem that i'm having is that when I click the button with the id, "killgroup", it does nothing. If you look above at my jquery code, the second section tries to react to that button click:
$('#killgroup').click(function(){
alert('made it');
});
});
I cannot get that to work. It seems as though there might be a chicken before the egg issue going on here but I am very new to jquery / javascript so I am not sure. Basically, I want to be able to click that dynamically created button and kick off another jquery script.