Create an Image Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image


You can create an <img> element by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction()">create an IMG element</button>

function myFunction() {/*from   w  ww  .j av a 2  s.c o m*/
    var x = document.createElement("IMG");
    x.setAttribute("src", "");
    x.setAttribute("width", "304");
    x.setAttribute("height", "200");
    x.setAttribute("alt", "alt message");


Related Tutorials