I do work with w3.css framework. Have a slide with caption in the middle. I want to use js i.e when I mouseOver caption color changes, when I mouseout background color gets back to its previous position. I have three same div blocks (HTML code shown below):
<div class="w3-display-container mySlides">
<img src="yellow.png" style="width:100%">
<div class="w3-display-middle w3-large w3-container w3-padding-16 w3-black hover">
HOVER TO MAKE ME TEAL
</div>
</div>
<div class="w3-display-container mySlides">
<img src="yellow.png" style="width:100%">
<div class="w3-display-middle w3-large w3-container w3-padding-16 w3-black hover">
HOVER TO MAKE ME TEAL
</div>
</div>
<div class="w3-display-container mySlides">
<img src="yellow.png" style="width:100%">
<div class="w3-display-middle w3-large w3-container w3-padding-16 w3-black hover">
HOVER TO MAKE ME TEAL
</div>
</div>
My javascript has some issue, but not sure what is wrong. (I am amateur javascript self-taught). My JS code (shown below):
document.getElementsByClassName("hover").addEventListener("mouseover", mouseOver);
document.getElementsByClassName("hover").addEventListener("mouseout", mouseOut);
var classChanged = document.getElementsByClassName("hover");
for (z = 0; classChanged.length; z++) { /* Iteration */
classChanged[z].style.backgroundColor = this; /* How to bind two functions shown below ?!*/
function mouseOver(classChanged) { /* binding with keyword THIS? */
classChanged.classList.remove("w3-black");
classChanged.classList.add("w3-teal");
}
function mouseOut(classChanged) { /* binding with keyword THIS? */
classChanged.classList.remove("w3-teal");
classChanged.classList.add("w3-black");
}
My mission is to apply functions to all three div blocks sharing the same class="... hover". Any help would be appreciated. Thank you. p.s I was managed to use getElementById() method to trigger first HTML block functions in order to change background color. Still only one. :'(