Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display image through html image element object

I have the following code :

function createImage(source) {                
var pastedImage = new Image();                
pastedImage.onload = function() {
                    
}
pastedImage.src = source;
}

The function createImage contain the source parameter which contain the source of an image. After that I created the object pastedImage of class Image and after alerting that I am getting the html image element object like [object HTMLImageElement].

My question is how I can display image into my html page using that object. I want to display it after onload function.

like image 443
J.K.A. Avatar asked Jun 04 '12 05:06

J.K.A.


1 Answers

Hiya : Working demo http://jsfiddle.net/wXV3u/

Api used = .html http://api.jquery.com/html/

In demo click on the click me button.

Hope this helps! Please lemme know if I missed anything! B-)

Code

$('#foo').click(function() {
    createImage("http://images.wikia.com/maditsmadfunny/images/5/54/Hulk-from-the-movie.jpg");

});

function createImage(source) {
    var pastedImage = new Image();
    pastedImage.onload = function() {

    }
    pastedImage.src = source;
    $(".testimonialhulk").html(pastedImage);
}​
like image 190
Tats_innit Avatar answered Sep 28 '22 06:09

Tats_innit