removing image tag from memory
Posted
by
Chapsterj
on Stack Overflow
See other posts from Stack Overflow
or by Chapsterj
Published on 2012-10-15T22:14:45Z
Indexed on
2012/10/15
23:02 UTC
Read the original article
Hit count: 114
jQuery
I have seen some code to check if a background image on a div is loaded. What they are doing is adding a img tag to memory but storing it in a variable and using that to see if the image is loaded with the load event. My question is does the $img tag stay in memory and how would I be able to remove that tag when the load event has been called.
var $div = $('div'),
bg = $div.css('background-image');
if (bg) {
var src = bg.replace(/(^url\()|(\)$|[\"\'])/g, ''),
$img = $('<img>').attr('src', src).on('load', function() {
// do something, maybe:
$div.fadeIn();
});
}
});
© Stack Overflow or respective owner