Why its recommended not use onclicks in your HTML.Use Event Handlers in your JS file is considered as best practice???
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can only have one handler with
on*.But no limits on the number of handlers you can attach to the same element for the same event when using the event registration model.
Besides, it helps consolidate all behavior within Javascript and not sprinkled throughout the codebase.
Note: you can attach events using on* inside your Javascript as well. The DOM event registration model was introduced to fix this very problem. See this example for more information:
Instead, a better approach is to use the event registration. Continuing the above example (this is just for demonstration and it’s not cross-browser),