I have three div's with the class of colorBox. I want to hover over each one of them and when I do that I want each of them to change their background color to a different. The problem is.. I don't know how to do that. I'm assuming that you need to use the this keyword. But, I don't think I'm using it right
CSS
<style type="text/css">
.colorBox{ width:200px; min-height:300px; color:white;
background:black; display:inline-block; padding:0 7px; text-align:center; }
.colorBox h2 { border-bottom:2px solid white;}
</style>
HTML
<div class="colorBox"><h2>Text Header</h2><p>Asymmetrical wolf letterpress, photo booth cornhole occupy tattooed portland fanny pack distillery offal roof party blog. Health goth cray four loko flannel 8-bit organic, gochujang waistcoat. Keytar franzen mumblecore, ennui stumptown etsy meditation YOLO cray 3 wolf moon waistcoat pop-up poutine tattooed austin. Shabby chic brooklyn keytar normcore whatever <p></div>
<div class="colorBox"><h2>Text Header</h2><p>Asymmetrical wolf letterpress, photo booth cornhole occupy tattooed portland fanny pack distillery offal roof party blog. Health goth cray four loko flannel 8-bit organic, gochujang waistcoat. Keytar franzen mumblecore, ennui stumptown etsy meditation YOLO cray 3 wolf moon waistcoat pop-up poutine tattooed austin. Shabby chic brooklyn keytar normcore whatever <p></div>
<div class="colorBox"><h2>Text Header</h2><p>Asymmetrical wolf letterpress, photo booth cornhole occupy tattooed portland fanny pack distillery offal roof party blog. Health goth cray four loko flannel 8-bit organic, gochujang waistcoat. Keytar franzen mumblecore, ennui stumptown etsy meditation YOLO cray 3 wolf moon waistcoat pop-up poutine tattooed austin. Shabby chic brooklyn keytar normcore whatever <p></div>
Javascript
(function(){
var a = document.getElementsByClassName('colorBox');
this.a = a;
this.style.background = 'black';
function hoverColor()
{
if (this.a == a[0])
{
this.style.background = 'green';
}
else if(this.a == a[1])
{
this.style.background = 'blue';
}
else if(this.a == a[2])
{
this.style.background = 'red';
}
}
for(var i = 0; i < a.length; ++i)
{
a[i].addEventListener('mouseover', hoverColor.bind(this));
}
})();