I'm trying to write a function that once the last image in an element is loaded it sets it as the parents background image only I cant seem to get it working...
I can alert the source but for some reason not affect the parent with no console errors?
https://jsfiddle.net/09ss43nx/1/
function swapImage(){
var elem = $('.team-member img:last-child');
if (!elem.prop('complete')) {
console.log("Waiting to be loaded!");
elem.on('load', function() {
elem.parent().css('background-image', elem.attr('src'));
});
} else {
elem.parent().css('background-image', elem.attr('src'));
}
}
swapImage();