jQuery <p> handle mouse enter and leave event

Description

jQuery <p> handle mouse enter and leave event

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Executing a Function on Mouseenter Event in jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<style>
    p{//w w  w .j a va  2s.co m
        padding: 20px;
        font: 20px sans-serif;
        background: #f2f2f2;
    }
    p.highlight{
        background: yellow;
    }
</style>
<script>
$(document).ready(function(){
    $("p").mouseenter(function(){
        $(this).addClass("highlight");
    });
    $("p").mouseleave(function(){
        $(this).removeClass("highlight");
    });
});
</script>
</head>
<body>
    <p>Place mouse pointer on me.</p>
    <p>Place mouse pointer on me.</p>
    <p>Place mouse pointer on me.</p>
</body>
</html>



PreviousNext

Related