An example. Try to keep index with 'data-index', and add/remove a class for 'selected'.
http://codepen.io/anon/pen/lzpCf
$('.triggers div')
.hover(function () { // on enter...
var thisIndex = $(this).data('index')
isClicked = $(this).hasClass('clicked');
if (!isClicked) {
$('.paragraphs p[data-index=' + thisIndex + ']').addClass('selected');
}
},
function () { // on leave...
var thisIndex = $(this).data('index');
isClicked = $(this).hasClass('clicked');
if (!isClicked) {
$('.paragraphs p[data-index=' + thisIndex + ']').removeClass('selected');
}
})
.click(function () { // on click...
$(this).toggleClass('clicked');
});
You can maybe clean-it up more and make one function to handle 'enter' and 'leave'. Just gave an example.