জয়েন লগইন

জাভাস্ক্রিপ্ট createEvent

🌈জাভাস্ক্রিপ্ট createEvent কি?

📋জাভাস্ক্রিপ্ট createEvent হলো নতুন ইভেন্ট তৈরি করার পদ্ধতি।

⚒️জাভাস্ক্রিপ্ট createEvent নতুন ইভেন্ট তৈরি করতে ব্যবহৃত হয়।

জাভাস্ক্রিপ্ট createEvent নতুন ইভেন্ট তৈরি করার উদাহরণ।

javascript
<!DOCTYPE html>
<html>
<body>

<button id="button">ক্রিয়েট</button>

<script>
function execute() {
  const event = document.createEvent("Event");

  event.initEvent("custom", true, true);

  button.dispatchEvent(event);
}

button.addEventListener("custom", () => {
  button.textContent = "ইভেন্ট";
});

execute();
</script>

</body>
</html>