JavaScript   

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>' +
                '</div>';
					
document.getElementById("parent-box").innerHTML = htmlCode;
Need Professional Support for Your Website Problems?

Whether you're facing website issues or struggling with code implementation, our team is here to assist. Hire us to get your website back on track.

Hire Us