Skip to content Skip to sidebar Skip to footer

Create Img In Jquery

How to create img tag in jQuery and set it as only content of some div? If target div has some content, replace it and put dynamically created img tag. Here is What I have tried:

Solution 1:

var $img=$("<img />",{"src":url});
$(target_id).html($img);

Solution 2:

You can create an Image object like this:

var img = new Image() 
img.src = 'image.jpg'

Post a Comment for "Create Img In Jquery"