Cristian
Cristian

Reputation: 69

Change values inside of CSS's "img" using JavaScript

<head>
    <style>
        img {
            opacity: 0.5;
        }
    </style>
</head>

This is a part of my HTML file. How do I change the value of the opacity using JavaScript?

Upvotes: 1

Views: 54

Answers (1)

jshawl
jshawl

Reputation: 3483

you can use style like:

var imgs = document.querySelectorAll("img");
for(let i = 0; i < imgs.length; i++){
  imgs[i].style.opacity = 1
}

Upvotes: 5

Related Questions