واحدة من أقوى ميزات jQuery هي التعامل مع الأحداث بسهولة. يمكنك استخدام العديد من الأحداث مثل "click"، "hover"، "keyup"، والمزيد.
<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>حدث hover باستخدام jQuery</title>
</head>
<body>
<div id="box" style="width: 100px; height: 100px; background-color: blue;"></div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$('#box').hover(
function() {
$(this).css('background-color', 'red');
},
function() {
$(this).css('background-color', 'blue');
}
);
</script>
</body>
</html>