Insert HTML content into modal window with Jquery

Asked

Viewed 130 times

0

I am loading content from a JSON file, formatting with Jquery and inserting inside the modal Bootstrap, the problem is that it does not learn the CSS formatting used.

Code to load JSON

$('.button').click(function(event){
    event.preventDefault();     
    $.getJSON('teste/teste.json', function(data) {
        var content  = '<div class="media">';
            content += '<img src="../../assets/other_img/bot-image.png" class="mr-3 mt-3 rounded-circle" style="width:60px;">';
            content += '<div class="media-body">';
            content += '<p>'+data.greeting+'</p>';
            content += '</div>';
            content += '</div>';

            $.each(data.menu, function(index, value)    {
                content += '<p class="badge badge-pill badge-primary">'+value+'</p>';  
            });

        $("#messageSent").html(content);    
    });

    $('.modal').modal('show'); 
});

Modal with loaded content and without formatting.

inserir a descrição da imagem aqui

  • What would be the CSS formatting used? Apparently, the tags are being inserted in text format.

  • Have you tried to verify if the error is how you are passing your content variable ? For example, instead of inserting this content, try to insert some html into this modal and see if it works. type a <p> abcdefgsdasdsa <p>, give a threshing ai and tell me what happens

  • Make sure that the element that has the id messageSent is a div.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.