Javascript – DOM appendChild example

Javascript DOM method appendChild can be used to append a child to existing DOM element. For example it can be used to append an Image, Template instance, etc. to an element. Here is an example which appends an image to an existing div.

<div id="id1">
<script type="text/javascript">
window.addEventListener("load", addImage);
function addImage() {
  var img = new Image();
  img.src = "/img/elephant1_small.jpg";

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments