I'm trying to manipulate what is happening in the fiddle on this forum, but I am having some trouble and I'm not sure where I am going wrong.
I have created my own pen here with a stripped down version of what is on my site.
Essentially what I want to do is whenever you hover over the image or the gray box, the body background color will change. (Ideally a fade in/out type of interaction, but if the fade part can be accomplished via CSS, I can do that).
I tried to changed getElementById (from the example) to getElementsByClassName since I have multiple instances of the class, but that didn't seem to work. I had added back in getElementById and it works where applied (on the image) but I don't think that would be best practice since I will have multiple instances of the class.
Disclaimer: I don't know much about JS, so if there is a better way to do this, I'd be glad to try it out!
I only added the JS in the post here to keep things condensed. HTML and CSS in the codepen.
$(document).ready(function(){
window.onload = function(){
var block1 = document.getElementById('hover-color1');
var body = document.body;
block1.onmouseover = function() {
body.className = 'hover-color1';
}
block1.onmouseout = function() {
body.className = '';
}
};
});