Insert an image inside an element through its class (HTML + JavaScript)

Example: CodePen

Code:

<div class="myClass"></div>

<script>
document.addEventListener('DOMContentLoaded', function() {
	document.getElementsByClassName("myClass")[0].innerHTML = "<img alt='my image' src='http://astralmemories.com/img/astral-memories-logo.png'>";
}, false);
</script>

Leave a Reply

Your email address will not be published. Required fields are marked *