So I have Bootstrap modal defined as:
   <div class="modal fade" id="myModal" role="dialog">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">×</button>
                    <h4 class="modal-title">Error</h4>
                </div>
                <div class="modal-body">
                    <p> </p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
And I want to edit the empty body with jscript. Im a beginner in Javascript so I'll appreciate the simplest answer.
const modal = document. createElement('div'); modal. classList. add('modal'); modal.id = 'modal'; modal.
Load Dynamic Content from Database in Bootstrap ModalBy clicking the Open Modal ( . openBtn ) button, the dynamic content is loaded from another PHP file ( getContent. php ) based on the ID and shows on the modal popup ( #myModal ).
Change the size of the modal by adding the . modal-sm class for small modals, . modal-lg class for large modals, or . modal-xl for extra large modals.
Bootstrap modals are supposed to be responsive by default. Something to look out for is if you have a width set on your Modal. For example I had a form body container inside of my modal with a height of 40rem.
Please have a look at this fiddle.
Here is the code:
$(function(){
  $('.custom-modal').click(function(e){
    e.preventDefault();
    var mymodal = $('#myModal');
    mymodal.find('.modal-body').text('hello');
    mymodal.modal('show');
  });
})
                        Try this one:
$('.modalShow').click(function(event){
    event.preventDefault();
    var e = $(this);
    var title = e.data('title');
    var body = e.data('value');
    $('.modal-title').html(title);
    $('.modal-body').html(body);
    $('#myModal').modal('show');
});
                        the simplest solution is - you can use javascript's innerHTML to change html of your modal body like this -
//get your modal body by class and change its html
document.getElementByClass("modal-body").innerHTML = "<p>some text</p>";
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With