Dynamically Add New Item With Id [closed]

On my page I add a div with id and then try to add something in it

document.getElementById('main_div').innerHTML = '<div id="new1"></div>';
....
document.getElementById('new1').innerHTML = 'HELLO';

Web page doesn’t recognise the new div (new1) that I added. “Uncaught TypeError: Cannot read properties of null” error occur. I think we must introduce the the new element before using it. But how can we do that?