I'm having an issue with inserting jQuery HTML string into HTML document, more specifically into footer of my body of the html.
The issue is when I append jQuery string which went through $.parseHTML
, it appears on my screen and I can inspect it. Nonetheless, after I open View page source, I can't find it in the HTML.
let chatWindow = '<section class="module"><header class="top-bar">' + userName + '</header>';
chatWindow += '<ol class="discussion">';
for (let i = data[0].length - 2; i >= 0; i -= 3) {
if (data[0][i - 1] == data[1]) {
chatWindow += '<li class="self"><div class="avatar"></div><div class="messages">';
} else {
chatWindow += '<li class="other"><div class="avatar">';
chatWindow += '<img src="' + data[2] + '"/></div><div class="messages">';
}
chatWindow += '<p>' + data[0][i] + '</p>';
}
chatWindow += '<time datetime="2009-11-13T20:00"></time></div></li></ol>';
chatWindow += '<textarea class="discussion-chat"></textarea></section>';
chatOutput = $.parseHTML(chatWindow);
console.log(chatOutput);
$('.module').css('display', 'block');
$('footer').append(chatOutput);
To clarify my clunky code, it's just a pop-up chat window which is generated through $.getJSON()
function.
When I use $.parseHTML
, it seems it gives me a correct format for DOM but append won't make it appear in the HTML.
Any ideas how can I insert chatWindow
var into my HTML?
Thank you