คุณสมบัติเคอร์เซอร์ถูกตั้งค่าหรือส่งคืนประเภทเคอร์เซอร์ที่จะแสดงสำหรับคุณสมบัติของเคอร์เซอร์
ต่อไปนี้เป็นรหัสสำหรับใช้งานคุณสมบัติเคอร์เซอร์ JavaScript -
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}
</style>
</head>
<body>
<h1>JavaScript Cursor property</h1>
<p class="sample"></p>
<h3>
Hover the mouse over the above paragraph after clicking the below button
</h3>
<button class="Btn">Change Cursor</button>
<script>
let sampleEle = document.querySelector(".sample");
document.querySelector(".Btn").addEventListener("click", () => {
sampleEle.style.cursor = "crosshair";
});
</script>
</body>
</html> ผลลัพธ์

เมื่อคลิกปุ่ม “เปลี่ยนเคอร์เซอร์” −
