user3454558 user3454558 - 1 year ago 121
HTML Question

How to add onclick to a html element dynamically using javascript

I am able to create a button element and add an onclick event as shown below.


How do I go about using a predefined function instead of defining a function inside of the event? Something like:


Answer Source

add an eventlistener to the element which has a defined function to call :

elem.addEventListener("click", func, false); //where func is your function name
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download