Add an Image to the DOM Dynamically

This example will work fairly well cross-browser. In IE it will use new Image and everything else it will use createElement. There are bugs in older IE versions with createElement and KHTML bugs with new Image() so we browser check and create the correct object.

var img = IEWIN ? new Image() : document.createElement('img');
img.src = '';

Leave a Reply

Your email address will not be published. Required fields are marked *