Append dynamic HTML block to an existing div tag using pure JavaScript?

Suppose we have the following div tag with an id parent-box and we want to insert custom HTML code inside it using JavaScript then we can use the below-given snippet.

<div id="parent-box">
</div >

JavaScript Code to append HTML block to the above tag

var htmlCode = '<div class="custom-content">' +
				'	<h2 class="heading">Hi, I am Custom Heading Text</h2>' +
                '	<div class="another-div">' +
                '	<div class="image-box">' +
				'		<img id="responsive-image" src="cool-image.png">' +
                '	</div>' +
                '	</div>' +
document.getElementById("parent-box").innerHTML = htmlCode;
Need a helping hand in fixing your website issues?

If you are facing any problems in implementing these code snippets and tutorials, you can hire us to fix your website issues.

Hire Us