0

Can I put a function in a function and use the one inside for onclick?

1st Apr 2022, 5:12 PM
Spencer Pawlik
Spencer Pawlik - avatar
3 odpowiedzi
+ 2
Yes Ipang is right. You can just set the onclick inside the func. Ex:- ... btn.onclick=function(){ ... }
1st Apr 2022, 6:02 PM
Chigozie Anyaeji 🇳🇬
Chigozie Anyaeji 🇳🇬 - avatar
+ 3
If you encapsulate an event handler, it would be better if you map the event to its handling function using addEventListener( ). If you mapped the event using HTML element's 'onclick' attribute, the event handler must not be encapsulated e.g. in global space.
1st Apr 2022, 5:33 PM
Ipang