JSFiddle - React, Tailwind, and code Playground

HTML

<div id="rects"></div>

JavaScript

// set Canvas
var R = Raphael('rects', 600, 500);

//Initialize variables
var i=0;
//Initialize y axis
var y=10; 

//Generate sets of rectangles
for (i=0;i<=5;i++){
    
    //Initialize set
    var set = R.set();
    //Initialize x axis
    var x=10;
    
    //Name of the set (for identify the ID later)
    var sname = set + i
    
    //Generate the rectangles for each set    
    for (n=0;n<=9;n++){
        var rectangle = R.rect(x,y,50,50);
        //set rectangle ID (using the set name as an identifier)
        rectangle.id = sname + "_" + n
        //Group the rectangles inside the Set
        set.push(rectangle);
        x = x + 60;
    }
    console.log(set);
    //Add unmouseover and onmouseout using Set.hover
    set.hover(function(){
        //Initialize a new String and store the id of the rectangle wich is being selected by the mouse event.
        var nameToStr = new String;
        nameToStr = this.id;
        console.log(nameToStr);
        //Split the string using the _ present in the ID thats separate the identifier of the set and the identifier of the current element.
        var strSplit = nameToStr.split('_');
        console.log(strSplit)
        //Store the name of the set.
        var setName = strSplit[0];
        var i=0;
        var currentRect = 1;
        //Loop trough all the elmenent inside the current Set and animate them.
        while(currentRect !== null) {
            
            var currentName = setName + '_' + i;
            console.log(currentName)
            currentRect = R.getById(currentName);
            if(currentRect){
                currentRect.animate({fill: '#000'}, 300);
                i++
            }
        }   
          
           
    });
    y = y + 60;
}