Actually this gets more complex as you need the hover to work both ways so more unique data-class="mar19_2016_1" and classes are needed class="mar19_2016_2"
Unless there is a more streamlined way of doing this, which Im sure there must be, Im not sure its worth the extra effort. Its not very elegant but it works, maybe someone else can come up with a solution which is a bit less cumbersome.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
<style>
* {
box-sizing: border-box
}
.col-wrapper {
display: flex;
width: 80%;
margin: 0 auto;
}
.col-wrapper h3 {
margin: 0;
padding: 10px;
font-size: 15px;
}
.col2 {
width: 30%;
padding: 30px;
}
.col2 h3:hover {
background-color: yellow;
cursor: pointer;
}
.col3 h3:hover {
background-color: yellow;
cursor: pointer;
}
.col3{
width: 70%;
padding: 30px;
}
</style>
</head>
<body>
<div class="col-wrapper">
<div class="col2">
<h1>Col 1</h1>
<h3 data-class="mar19_2016_1" class="mar19_2016_2">19 Mar 2016</h3>
<h3 data-class="mar22_2016_1" class="mar22_2016_2">22 Mar 2016</h3>
<h3 data-class="apr22_2016_1" class="apr22_2016_2">22 Apr 2016</h3>
<h3 data-class="jun11_2016_1" class="jun11_2016_2">11 Jun 2016</h3>
<h3 data-class="jul20_2016_1" class="jul20_2016_2">20 Jul 2016</h3>
<h3 data-class="jan16_2017_1" class="jan16_2017_2">16 Jan 2017</h3>
<h3 data-class="mar9_2017_1" class="mar9_2017_2">9 Mar 2017</h3>
<h3 data-class="aug31_2015_1">31 Aug 2015</h3>
<h3 data-class="feb10_2016_1">10 Feb 2016</h3>
<h3 data-class="mar15_2016_1">15 Mar 2016</h3>
</div>
<div class="col3">
<h1>Col 2</h1>
<h3 data-class="mar19_2016_2" class="mar19_2016_1">Title: Inflation and the Euro</h3>
<h3 data-class="mar22_2016_2" class="mar22_2016_1">Title: Americans must choose their own president.</h3>
<h3 data-class="apr22_2016_2" class="apr22_2016_1">Title: We are oblivious of the inflation seeping underground.</h3>
<h3 data-class="jun11_2016_2" class="jun11_2016_1">Title: Book Value, Intrinsic Value, and the Value of Sovereignty</h3>
<h3 data-class="jul20_2016_2" class="jul20_2016_1">Title: Who is writing the history in 2016, establishment or grass roots?</h3>
<h3 data-class="jan16_2017_2" class="jan16_2017_1">Title: The Movement and A New Paradigm - challenge to and choice by the grass roots</h3>
<h3 data-class="mar9_2017_2" class="mar9_2017_1">Title: Fetish for Another Bubble</h3>
</div>
</div>
<!-- end col-wrapper -->
<script>
const col2h3 = document.querySelectorAll('.col2 h3');
const col3h3 = document.querySelectorAll('.col3 h3');
col2h3.forEach(function(date) {
date.addEventListener('mouseenter', getDateMouseEnter);
})
col2h3.forEach(function(date) {
date.addEventListener('mouseleave', getDateMouseLeave);
})
col3h3.forEach(function(date) {
date.addEventListener('mouseenter', getDateMouseEnter);
})
col3h3.forEach(function(date) {
date.addEventListener('mouseleave', getDateMouseLeave);
})
function getDateMouseEnter() {
var date = this.getAttribute('data-class');
var currentDate = document.querySelector('.' + date);
currentDate.style.backgroundColor = "yellow";
}
function getDateMouseLeave() {
var date = this.getAttribute('data-class');
var currentDate = document.querySelector('.' + date);
currentDate.style.backgroundColor = "";
}
</script>
</body>
</html>