jQuery mouseenter() trigger mouse enter event

Description

jQuery mouseenter() trigger mouse enter event

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//  www.  j  a va2  s .  c  o m
<script>
$(document).ready(function(){
  $("p").mouseenter(function(){
    $("p").css("background-color", "yellow");
  });
  $("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>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<button id="btn1">Trigger mouseenter event</button><br>
<button id="btn2">Trigger mouseleave event</button>

</body>
</html>



PreviousNext

Related