html - How to display image with JavaScript? -


I am trying to display the image via javascript, but I can not understand how to do this . I have the following

  function image (a, b, c) {this.link = a; This.alt = b; This.thumb = c; } Function show_image () {document.write ("img src =" + this.link + "& gt;"); } Image1 = new image ("img / img1.jpg", "dsfdsfdsfds", "thumb / img3");   

In HTML

  & lt; P & gt; & Lt; Input type = "button" value = "Vytvor" onclick = "show_image ()" & gt; & Lt; / P & gt;   

I do not know that I image1.show_image (); .

Something like HTML should be? Or, somewhere else ...

You can use this specially, see the method.

You can create a usable function that will create an image like this ...

  function show_image (src, width, height, alt) {var Img = document.createElement ("img"); Img.src = src; Img.width = width; Img.height = Height; Img.alt = alt; // This next line just & lt; Body & gt; Tag document.body.appendChild (img); }   

Then you can use it like this ...

  button onclick = "show_image ('http://google.com/ Images /logo.gif ', 276, 110,' Google logo '); "& gt; Add Google logo & lt; / Button & gt;   

See an example on jsFiddle:

Comments