Starlit Daily

📚 › JavaScript: make pages do things

12. Events in the browser

ستتم ترجمة هذا المقال تلقائيًا. يُعرض بالإنجليزية حاليًا.

JavaScript reacts to events such as clicks. addEventListener('click', function) runs your code when the element is clicked. document.querySelector finds an element by its CSS selector.

This is how pages respond to visitors.

عرض المثال

const btn = document.querySelector("#go");
btn.addEventListener("click", () => alert("Clicked"));

✍️ دورك الآن

Print the text Event ready. Use console.log only, the runner has no page.

← العودة إلى الدورة