$( function() { $(document) .on( 'change', '.gw-image-input', function(e) { var input = this; $.ajax( { url: '/admin/imagemanager/manager/view', type: "POST", data: { 'ImageManager_id': input.value }, success: function(data) { $( '#' + $(input) .data('img') ) .attr('src', data.image); $( '#' + $(input) .data('name') ) .html(data.fileName); } } ); } ); $(document) .on( 'click', '#add-image', function(e) { var hash = Math.floor(Math.random() * 89999) + 10000; var content = '
' + '
' + '

' + '
'; $('.gw-container').append(content); // if (document.querySelectorAll(".gw-container > .gw-item").length % 3 === 0) { // $('.gw-container').append('
'); // } } ); $(document) .on( 'click', '.remove-img', function(e) { $(this).parent().parent().remove(); } ) } );