Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript opacity translation from css Reply To: opacity translation from css

#168892
dyr
Participant

You’ll need to set the style property of the element.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement.style

With Javacript you’ll need to get a reference to the element whose styles you wish to change. This could be an ID or class.

For example, given the following HTML:

<div id="myDiv"></div>

You could write something like:

// grab the element we want to apply styles to
var el = document.getElementById('myDiv');

// change the background color style property to this rgb value
el.style.backgroundColor = "rgb(0, 0, 0)";

You can alter any css property this way!

Cheers