function aggiungiClasseAiMedia() {
    console.log(media_ids);
    media_ids.forEach(function(mediaId) {
        var mediaElement = jQuery('[data-id="' + mediaId + '"]');
        mediaElement.addClass('s3-class');

        var postElement = jQuery('#post-' + mediaId);
//        postElement.find('span').addClass('s3-class');
        var imagesInTargetClass = postElement.find('.column-primary span:first');
        imagesInTargetClass.addClass('s3-class');
    });
}

jQuery(document).ready(function() {
    aggiungiClasseAiMedia();

    jQuery(document).on('DOMNodeInserted', function(e) {
        var target = jQuery(e.target);
        if (target.hasClass('attachment') && target.attr('data-id')) {
            aggiungiClasseAiMedia();
        }
    });
});