Using jQuery on() Instead of hover()

Using jQuery on() Instead of hover() ,Example of what you get using jquery hover()
Share it:
Using jQuery on() Instead of hover()
google


jQuery hover()

hover is a jQuery function that can trigger two functions when the mouse enters and leaves an element on the current page.

Example of what you get using jquery hover()

In this example, when the mouse enters each line of the table, a CSS class is added. Then when the mouse leaves the current line, the previous CSS class is removed.button is clicked, the first, third, and fifth block will be selected and get their containers filled with a background color.


Line 1
Line 2
Line 3
Line 4
Line 5



Step 1

You need to add the elements that will get the effects triggered by the hover() function. In our example, each line of the table will get a temporary CSS background when the mouse rollover them
12345678910111213
<style type="text/css">
.hover{
 background-color:#DDD;
}
</style>

<table>
 <tr><td>Line 1</td></tr>
 <tr><td>Line 2</td></tr>
 <tr><td>Line 3</td></tr>
 <tr><td>Line 4</td></tr>
 <tr><td>Line 5</td></tr>
</table>
Step 2

The following jquery indicates that when the mouse enters a cell of the table (td Html element), the CSS class "hover" is applied to the cell. Then when the mouse leaves the cell, the CSS class "hover" is removed.

12345678910111213
<script type="text/javascript">
$('td').hover(
 function(){
  $(this).addClass('hover');
 },
 function(){
  $(this).removeClass('hover');
 }
);
</script
Do you know:-

If you like the tutorial, then please share this tutorial with your friends on social media.
Share it:

jQuery

Post A Comment:

0 comments: