Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set opacity of an element using JS?

I know how to set it in a style sheet. This explains how to get it using JS...

I tried this to set it:

window.getComputedStyle( myEl ).setPropertyValue( 'opacity', 0.7 );

and got

setPropertyValue is not a function.

Obviously I can use JQuery css( ... )... in the min.js file I found there were no fewer than 10 matches for opacity. I didn't have a clue about what was going on.

This is Firefox, by the way.

like image 677
mike rodent Avatar asked Sep 03 '25 07:09

mike rodent


1 Answers

By modifying the style property.

myEl.style.opacity = 0.7;
like image 172
Mike Cluck Avatar answered Sep 04 '25 21:09

Mike Cluck