Monday, July 15, 2019

[JavaScript][Dom][Example] Create image node

I searched there are 2 method to create img node with js, you can create an Image() object or simply create element.
<script>
<div id="content"></div>
<script>
var img1= new Image();
img1.src="https://mesh-uploads-legacy.s3.amazonaws.com/mesh-control/d35d13d303ca403e847bd587e514b87e_size-logo.png";
document.getElementById("content").appendChild(img1);
var img2 = document.createElement("img");
img2.src="https://mesh-uploads-legacy.s3.amazonaws.com/mesh-control/d35d13d303ca403e847bd587e514b87e_size-logo.png";
document.getElementById("content").appendChild(img2);
</script>

Result :


No comments :

Post a Comment