I'm trying to highlight all elements of the same class (person1, person2, etc.) that are created dynamically with JavaScript from an array, when hovering over one element from this class. F.e. if I hover over an element with class: person1 I would like all elements with class: person1 to be highlighted. The main problem is that when I add a parameter to the highlightGen function that's added onmouseover (which would be highlightGen(j) ) to then work on each person1, person2, person3 depending on the situation through this variable, the function stops working all together. This is what I've come up with so far.
[update]: I've tried Your example, but the same effect occurs when I added parameters to the highlightGen function - not responding. I attach the codepen, so maybe someone will be able to figure why it's not responding to mouseenter.
https://codepen.io/mmsmsy/pen/zZddZz
jQuery UI function:
function highlightGen() {
$(this).addClass('hovered', 300);
}
function highlightGenNot() {
$(this).removeClass('hovered', 300);
}
And part of the code in a JavaScript loop creating elements from an array:
var div = document.createElement('div');
var divIdInitial = tree[j].name.toLowerCase();
var find = ["ą","ć","ę","ł","ń","ó","ś","ź","ż"," "];
var replace = ["a","c","e","l","n","o","s","z","z",""];
var divId = divIdInitial.replaceArray(find,replace) + tree[j].genNum;
div.setAttribute('id',divId);
var divClass = 'person person' + tree[j].genNum;
div.setAttribute('class',divClass);
div.onmouseover = highlightGen;
div.onmouseout = highlightGenNot;