$('body').on('click', function () {
$( '.detailTextContainer a' ).each(function() {
var urlFoto = $(this).attr('href');
var imgElement = $("<img />").attr('src', urlFoto)
.addClass('dalsiFoto');
$(this).empty().append( imgElement );
});
});
How can I run this function automatically after load page (without event). '.detailTextContainer a'
are dynamic elements, which are loaded to page immediately after start page.
I tried this code:
function showImage (){
$( '.detailFeatureDesc a' ).each(function() {
var urlFoto = $(this).attr('href');
var imgElement = $("<img />").attr('src', urlFoto)
.addClass('dalsiFoto');
$(this).empty().append( imgElement );
});
};
showImage();
But this weren't successfully.
Thanks
You can use load function:
From documentation, this will run the function when the page is fully loaded including graphics.
Or you can use:
or the shorthand:
This will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.