I have a project where we have multiple modals on same page. So the idea is to get the id from the button that is clicked and append that id to the modal. Example is:
Here is my code in plunker: bootstrap modal
<button class="btn btn-readmore" data-toggle="modal" href="modals/serv-cutting.html" data-target="#vividCutting">read more</button>
<button class="btn btn-readmore" data-toggle="modal" href="modals/serv-color.html" data-target="#vividColor">read more</button>
then add that id attribute to:
<div class="modal fade" tabindex="-1" role="dialog" aria- labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog"><div class="modal-content"></div>
</div>
</div>
So I have quite a few modals and i came up with this jQuery as if I dont remove the id first, then all the buttons that trigger modals just keep opening the same modal:
$('button.btn-readmore').click(function() {
var newId = $(this).attr('data-target').slice(1);
console.log(newId);
if($('.modal').prop('id', newId)){
$(this).removeProp('id', newId);
} else {
$('.modal').prop('id', newId)
}
});
I think Im close but need a little advice.