jQuery hover () الطريقة

❮ طرق أحداث jQuery

مثال

غيّر لون الخلفية لعنصر <p> عندما يحوم مؤشر الماوس فوقه:

$("p").hover(function(){
  $(this).css("background-color", "yellow");
  }, function(){
  $(this).css("background-color", "pink");
});

التعريف والاستخدام

تحدد طريقة hover () وظيفتين ليتم تشغيلهما عندما يحوم مؤشر الماوس فوق العناصر المحددة.

تؤدي هذه الطريقة إلى تشغيل أحداث Mouseenter و mouseleave .

ملاحظة: إذا تم تحديد وظيفة واحدة فقط ، فسيتم تشغيلها لكل من حدث Mouseenter و mouseleave.


بناء الجملة

$(selector).hover(inFunction,outFunction)

Parameter Description
inFunction Required. Specifies the function to run when the mouseenter event occurs
outFunction Optional. Specifies the function to run when the mouseleave event occurs

❮ طرق أحداث jQuery