trigger the mouseleave event for the selected elements: - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:mouseleave

Description

trigger the mouseleave event for the selected elements:

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(){
    $("p").mouseenter(function(){
        $("p").css("background-color", "yellow");
    });//from   w  w  w .ja  v a  2 s.  com
    $("p").mouseleave(function(){
        $("p").css("background-color", "lightgray");
    });
    $("#btn1").click(function(){
        $("p").mouseenter();
    });
    $("#btn2").click(function(){
        $("p").mouseleave();
    });
});
</script>
</head>
<body>

<p>This is a paragraph.</p>

<button id="btn1">Trigger mouseenter event</button><br>
<button id="btn2">Trigger mouseleave event</button>

</body>
</html>

Related Tutorials