I
I
Ilya Famin2021-06-11 16:21:21
JavaScript
Ilya Famin, 2021-06-11 16:21:21

How to upload an image only to the block in which it was selected?

The bottom line is that on the page with adding posts there is a button for adding another form for adding a post, and I need it so that when uploading a photo or video to one post, it does not appear in another

function readURL(input) {

    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('.left-part-new-post').find('.preload-img').attr('src', e.target.result);
        };

        reader.readAsDataURL(input.files[0]);
    }
}
$(".add-file-post").change(function () {
    readURL(this);
    $('.main-form').remove();
});

Can you suggest any related sites?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WapSter, 2021-06-11
@Fama18122000

The algorithm is something like this, just think a little and you can finish it to fit your needs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question