jQuery HTML Element How to - Dynamically load image








Question

We would like to know how to dynamically load image.

Answer


<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
</head><!--from   ww  w  . ja  v  a2  s.c o  m-->
<body>
  <div id="imgwrapper"></div>
  <script>
    img = document.createElement("img"); 
    
    img.src = "http://www.java2s.com/style/download.png"; 
    $('#imgwrapper').append(img); 
    
    </script>
</body>
</html>

The code above is rendered as follows: