Run first function when mouse enters the HTML element, and run the second function when the mouse leaves the HTML element - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:hover

Description

Run first function when mouse enters the HTML element, and run the second function when the mouse leaves the HTML element

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("#p1").hover(function(){
        console.log("You entered p1!");
    },/*ww  w .j  a  va  2s  . c om*/
    function(){
        console.log("Bye! You now leave p1!");
    });
});
</script>
</head>
<body>

<p id="p1">This is a paragraph.</p>

</body>
</html>

Related Tutorials