how to change svg color on mouseover inside a foreach cycle

Viewed 15

I have a button inside a foreach() cycle. The button has an "svg" inside. I want to change the svg color to white only for the button where the mouse hovers at. By setting an id for the svg, it changes the color only of the first svg, independently from which user i chose.

foreach(var item in Model.Users){<tr><td>
<a href="#AddDataModal" class="svg1 btn btn-sm btn-outline-success border-0 font-weight-bold" data-toggle="modal" data-userid="@item.Id" style="width:80px;" onmouseover="svg1.style.fill='white';" onmouseout="svg1.style.fill='blue';">
 <svg id="svg1" width="12pt" height="12pt" viewBox="0 0 128 128" version="1.1" xmlns="http://www.w3.org/2000/svg"></svg></a></th></td></tr>} 
                                              
1 Answers

#svg1{
  fill : #000;
  transition : 0.5s ease
  curusor : pointer
}

#svg1:hover{
  fill :#f00
}
<svg id="svg1" stroke-width="0" viewBox="0 0 16 16" class="mx-2 text-mainColor" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M4 1c2.21 0 4 1.755 4 3.92C8 2.755 9.79 1 12 1s4 1.755 4 3.92c0 3.263-3.234 4.414-7.608 9.608a.513.513 0 0 1-.784 0C3.234 9.334 0 8.183 0 4.92 0 2.755 1.79 1 4 1z"></path></svg>

Related