I have the following script in the head Element:
<script>
function changeOpacity(className) {
var elems = document.getElementsByClassName(className);
var index = 0, length = elems.length;
for ( ; index < length; index++) {
elems[index].style.transition = "opacity 0.3s linear 0s";
elems[index].style.opacity = 0.8;
}
}
</script>
<style>
.red_box {width:100px;height:100px;opacity:1;background:red}
</style>
and the following structure in the body Element:
<div onmouseover="changeOpacity('.red_box')">Click to fade red boxes</div>
<div class="red_box">Box 1</div>
<div class="red_box">Box 2</div>
<div class="red_box">Box 3</div>
I'm trying to achieve the following: when the user clicks on the 'Click to fade red boxes' message, the function should make each div with the class: 'red_box' to turn transparent. I would love some pointers (not Jquery please), Thanks!
1in the CSS, and then your JavaScript code also sets it to1. Did you mean to set it to0?