How to append String to a Div in JavaScript

Use innerHTML. If you want to change the div content, use = or if you want to append something to the content that already exists, use +=.

    document.getElementById('yourElementId').innerHTML += 'Your Value';

    // or

    document.getElementById('yourElementId').innerHTML = 'Your Value';

Example 1:

Change the div content

<div id="result">Waiting for result</div>

    document.getElementById('result').innerHTML = 'Hello';

Output: Hello

Example 2:

Append text to the div without changing its content.

<div id="result">Result: </div>

    document.getElementById('result').innerHTML += 'Hello';

Output: Result: Hello