คุณสมบัติ cursor ใช้ตั้งค่าหรือคืนค่าประเภทของเคอร์เซอร์ที่จะแสดงสำหรับองค์ประกอบ
โค้ดตัวอย่างสำหรับการนำ JavaScript Cursor property ไปใช้งาน ดังนี้ -
ตัวอย่าง
<!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> วางเมาส์เหนือย่อหน้าข้างบนหลังจากคลิกปุ่มด้านล่าง </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>
ผลลัพธ์

เมื่อคลิกปุ่ม "Change Cursor" -
