0

How to change the onclick property of an html element with JavaScript?

I am making a calculator and I want to change the onClick function, when we click any other element.

13th Jul 2017, 10:03 AM
Aryan Gupta
Aryan Gupta - avatar
2 Answers
+ 5
Get the element reference, for example: var eref = document.getElementById('myElementID'); ... and use its .addEventListener() method: e.ref.addEventListener('click', function() { /* code */ }); Obviously, you can provide a function name already declared ;)
13th Jul 2017, 10:33 AM
visph
visph - avatar
0
thanks man
13th Jul 2017, 1:03 PM
Aryan Gupta
Aryan Gupta - avatar