Add image element to DIV using JavaScript

Last Reply 11 months ago By chetan

Posted 11 months ago

Is it possible to call an image as a class and display it on page?

like

<div class="catimage"></div>

 

Posted 11 months ago

kindly refer the below.

<html>
<body>
<script type="text/javascript">
    window.onload=function(){
        var elem = document.createElement("img");
        elem.setAttribute("src", "http://img.zohostatic.com/discussions/v1/images/defaultPhoto.png");
        elem.setAttribute("height", "768");
        elem.setAttribute("width", "1024");
        elem.setAttribute("alt", "Flower");
        document.getElementById("placehere").appendChild(elem);
    }
</script>
<div id="placehere">
</div>
</body>
</html>