js_events.md - brainchildservices/curriculum GitHub Wiki
Slide 1
JAVASCRIPT ONCLICK EVENT
- The onclick event generally occurs when the user clicks on an element. It allows the programmer to execute a JavaScript's function when an element gets clicked.
- The JavaScript onclick function is designed to execute code when users interact with the HTML elements. The onclick JavaScript can be applied to any HTML element.
WHY
- The JavaScript onclick event is one of the most frequently utilized event types. It's a common practice to enhance websites by adding some functionality such as JavaScript button click or other elements.
- This event can be used for validating a form, warning messages and many more.
SYNTAX - JS ONCLICK
-
object.onclick = function() { myScript }; [IN JAVASCRIPT]
-
object.addEventListener("click", myScript); [In JavaScript by using the addEventListener() method]