Removed deprecated document.createEvent() and replaced with new CustomEvent() for custom event creation