Implementation of hover by live in jquery
Html
| The Code is as follows: |
|
| <Ul id = "Hover"> <Li> Title <I class = "modify" style = "display: none"> modify </I> <I class = "delete" style = "display: none "> Delete </I> </li> <Li> Title <I class = "modify" style = "display: none"> modify </I> <I class = "delete" style = "display: none "> Delete </I> </li> <Li> Title <I class = "modify" style = "display: none"> modify </I> <I class = "delete" style = "display: none "> Delete </I> </li> </Ul> |
Js
| The Code is as follows: |
|
| // The following code does not work for the elements dynamically added by js. You need to replace on. $ ("Li", "# Hover"). hover (function (){ $ (". Modify,. delete", $ (this). show (); }, Function (){ $ (". Modify,. delete", $ (this). hide (); }); // Jquery 1.9 uses the on binding event, and the mouse displays the modification and deletion effects. $ ("# Hover"). on ({ Mouseenter: function (){ $ (". Modify,. delete", $ (this). show (); }, Mouseleave: function (){ $ (". Modify,. delete", $ (this). hide (); } }, "Li"); // descendant selector |
Hover is not a standard event, so live cannot be used directly for processing. Therefore, use the following method instead, with the same effect.
| The Code is as follows: |
|
| $ ("Table tr"). live ({ Mouseenter: Function () { // Todo }, Mouseleave: Function () { // Todo } }); |