shahr's avatar
Level 10

How to add class after upload an image?

Why this code is not working?

 function previewFile() {
    var preview = document.querySelector('img');
    var file    = document.querySelector('input[type=file]'='class="rounded-circle"').files[0];
    var reader  = new FileReader();

    reader.addEventListener("load", function () {
        preview.src = reader.result;
    }, false);

    if (file) {
        reader.readAsDataURL(file);
    }
}

I want to add class of rounded-circle after upload an image.

0 likes
1 reply
artcore's avatar
document.querySelector('img').classList.add('rounded-circle');

Isn't a circle always round ;)

Please or to participate in this conversation.