Question

The default background color of a "p" element is aqua. How can I change it to coral color when the mouse pointer hovers over the element?

1 Answers

$(selector).hover(overFn, outFn)

The overFn is a callback function that runs when the mouseenter event occurs i.e. when the mouse is moved over a matched element.

The outFn is a callback function that runs when the mouseleave event occurs i.e. when the mouse is moved off a matched element.

<p style = "background-color:aqua;">Learning jQuery</p>

<script>

  $("p").hover(
    //Code for hover over
    function(){
      $(this).css("background-color", "coral");
    },
    //Code for Hover out
    function(){
      $(this).css("background-color", "aqua");
    }
  );
</script>