English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery mouseenter() method

Événements jQuery

The mouseenter() method triggers the mouseenter event, or attach a function to be executed when the mouseenter event occurs.

A mouseenter event occurs when the mouse pointer enters the element.

You might think mouseenter,mousemoveandmouseoverThe event is the same, but they are not:

  • mouseenter-Call only when the mouse pointer enters the element

  • mousemove-Call when the mouse pointer is moved to the element

  • mouseover-Call when the mouse pointer enters the element and its child elements (see the following example)

The mouseenter() method is usually used withmouseleave()methods are used together.

Syntax:

Trigger the mouseenter event of the selected element:

$(selector).mouseenter()

Ajouter une fonction à l'événement mouseenter :

$(selector).mouseenter(function)

Exemple

Changer la couleur de fond lors du déclenchement des événements mouseenter et mouseleave :

$("p").mouseenter(function(){
  $(this).css("background-color", "yellow");
});
$("p").mouseleave(function(){
  $(this).css("background-color", "lightblue");
});
Vérifiez et voyez‹/›

Cet exemple montre la différence entre mousemove, mouseenter et mouseover :

Événement Mouseenter appelé :

Événement de souris appelé :

Événement de souris appelé :

Exécuter le code

Valeur du paramètre

ParamètresDescription
functionFonction exécutée lors du déclenchement de l'événement mouseenter

Événements jQuery