Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace innerHTML with jQuery?

I have written the code below but now I have to write this with jQuery because of security reasons. I have never done something with jQuery before and I really don't know, how to write this. I shouldn't mix the HTML with JS and should use createElement and stuff like that.

var demoName1 = "Peter Stone";
function showMessage() {
    var newMsg = '<div id="messageBoxSend">' +
        '<div class="nameSend">' + demoName1 + '</div>' +
        '<div class="text">' +
        ' <div id="FscToolPaneNoseSend">' +
        '</div></div>' +
        document.getElementById('inputText').value;

var a = new Date();
    var b = a.getHours();
    var c = a.getMinutes();
    if (c < 10) {
        c = "0" + c;
    }
    var time = b + ':' + c;

    newMsg += '<div class="time">' + time + '</div>' +
        ' </div></div><br>';
...
}
like image 568
candy fan Avatar asked Sep 14 '25 19:09

candy fan


1 Answers

You will try this code

$('class or id').html('');

$('class or id').html(newMsg);

like image 63
Lokendra Singh Panwar Avatar answered Sep 16 '25 08:09

Lokendra Singh Panwar