Javascript examples for DOM HTML Element:Image
You can create an <img> element by using the document.createElement() method:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">create an IMG element</button> <script> function myFunction() {/*from w ww .j av a 2 s.c o m*/ var x = document.createElement("IMG"); x.setAttribute("src", "http://java2s.com/resources/a.png"); x.setAttribute("width", "304"); x.setAttribute("height", "200"); x.setAttribute("alt", "alt message"); document.body.appendChild(x); } </script> </body> </html>