I'm using this simple jquery plugin for modal popups but it doesn't have a function for multiple popups so I'm trying to make my own.
First I added unique indexes to the buttons that open the modal and the modal divs. The HTML is created dynamically.
<button class="my_modal_open" id="1">Open modal</button>
<div id="my_modal" class="1" style="display:none;margin:1em;">
<a href="#" class="my_modal_close" style="float:right;padding:0 0.4em;">×</a>
Modal Content
</div>
<button class="my_modal_open" id="2">Open modal</button>
<div id="my_modal" class="2" style="display:none;margin:1em;">
<a href="#" class="my_modal_close" style="float:right;padding:0 0.4em;">×</a>
Modal Content
</div>
<button class="my_modal_open" id="3">Open modal</button>
<div id="my_modal" class="3" style="display:none;margin:1em;">
<a href="#" class="my_modal_close" style="float:right;padding:0 0.4em;">×</a>
Modal Content
</div>
And then I modified the js to open modals by appropriate index.
$(document).ready(function() {
$('.my_modal_open').click( function() {
$('#my_modal').css('display','none'); //added
var open_id = $(this).attr('id'); //added
$('#my_modal.' + open_id).popup(); //changed to get div id and class
});
});
This works but the modals open only once. As a fix I tried adding
$('#my_modal').css('display','block');
after the popup()
function which works but the modal doesn't display in the right position, the second time.
Please share any suggestions. Hopefully someone used this plugin before.