So I'm fairly new to jquery and I'm trying to get the dynamically generated ID's of my modals. So this is what my code looks like:
<?php
$sql = "SELECT * FROM currentstatus";
$res = mysql_query($sql);
while($r = mysql_fetch_assoc($res)) {
echo '<div class="modal fade" id="'.$r['rackName'].'" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">'.$r['rackName'].'</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Print</button>
</div>
</div>
</div>
</div>';
}
?>
.$['rackName'] is my dynamic ID
I call this modal, using the following code:
<a href="" data-toggle="modal" data-target="#'.$r['rackName'].'">'.$r['rackName'].'</a>
You can capture the show event and get the ID like so:
$(function(){
$('.modal').on('show.bs.modal', function () {
console.log( $(this).prop('id') );
});
});