Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Make thumbnail big and small with onclick event

enter image description here

I’ve trying for a couple hours to make the thumbnail (image in my html) big when clicking it and small when clicking it again but it only gets bigger, and not smaller when clicking it for another time; the small class is in my css code, Here’s my code:

document.addEventListener("DOMContentLoaded", () => {

    let thumbnail = document.getElementById("smart_thumbnail");

    thumbnail.onclick = () => {
        thumbnail.className = ""
    }
        
    if (thumbnail.className == "") {
        
        thumbnail.onclick = () => {
            thumbnail.className = "small"
        }

    } else {

        thumbnail.className = "small"

    }

})

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

document.addEventListener("DOMContentLoaded", () => {
    const thumbnail = document.getElementById("smart_thumbnail");

    thumbnail.onclick = () => {
        thumbnail.classList.toggle('small');
    }
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading