jQuery .hover( handlerIn, handlerOut ) bind one or two handlers to the matched elements, to be executed when the mouse pointer enters and leaves the elements.


The .hover() method binds handlers for both mouseenter and mouseleave events. You can use it to simply apply behavior to an element during the time the mouse is within the element.
Calling $( selector ).hover( handlerIn, handlerOut ) is shorthand for:
$(selector).mouseenter(handlerIn).mouseleave(handlerOut);
  • handlerIn – function to call when the mouse enters the matched element.
  • handlerOut – function to call when the mouse leaves the matched element.
Example:
$("#myTable tr").not(':first').hover(
  function () {
    $(this).addClass("highlightYellow");
  },
  function () {
      $(this).removeClass("highlightYellow");
  }
);
});
It will highlight the table row record on hover, with color of yellow. The “.not(‘:first’)” is common implementation to avoid highlight the header row record.
<html>
<head>
<script type="text/javascript"
 src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<h1>jQuery - Highlight table row record on hover</h1>
<table border="1" id="myTable">
    <tr><th>N#</th><th>Name</th><th>Age</th><th>Salary</th></tr>
    <tr><td>1</td><td>Jimmy Y.</td><td>45</td><td>$80,000</td></tr>
    <tr><td>2</td><td>George B. </td><td>32</td><td>$50,000</td></tr>
    <tr><td>3</td><td>Paul S.</td><td>46</td><td>$50,000</td></tr>
    <tr><td>4</td><td>Christopher P.</td><td>18</td><td>$40,000</td></tr>
    <tr><td>5</td><td>James Y.</td><td>17</td><td>$30,000</td></tr>
</table>
<script type="text/javascript">
$(function(){
    $("#myTable tr").not(':first').hover(
      function () {
          $(this).addClass("highlightYellow");
      },
      function () {
          $(this).removeClass("highlightYellow");
      }
    );
});
</script>
</body>
</html>

jQuery - Highlight table row record on hover

N#NameAgeSalary
1Jimmy Y.28$80,000
2George B. 29$50,000
3Paul S.18$50,000
4Christopher P.28$40,000
5James Y.28$30,000