I have the following code:
.line-item:hover td {
background-color: yellow;
}
.item-text:focus + .line-item td {
background-color: red !important;
}
<table border="1">
<tr class="line-item">
<td>L1C1</td>
<td>L1C2</td>
<td><input class="item-text" type="text" /></td>
</tr>
<tr class="line-item">
<td>L2C1</td>
<td>L2C2</td>
<td><input class="item-text" type="text" /></td>
</tr>
</table>
The goal is to leave the line where text
was focused red.
Desiredoutcome:
Whenyouhoveroveranyelementyounoticethatthelineis Yellow.WhenIclickonthetextIwouldlikethelinetoturnred.
UsingJavaScriptwouldlooklikethis:
$(".item-text").focusin(function(){
$(this).closest(".line-item").css("background-color", "red");
}).focusout(function(){
$(this).closest(".line-item").css("background-color", "transparent");
});
.line-item:hover td {
background-color: yellow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><tableborder="1">
<tr class="line-item">
<td>L1C1</td>
<td>L1C2</td>
<td><input class="item-text" type="text" /></td>
</tr>
<tr class="line-item">
<td>L2C1</td>
<td>L2C2</td>
<td><input class="item-text" type="text" /></td>
</tr>
</table>