In JavaScript, we can add multiple functions to body’s onload or a button’s onclick. Is it possible to remove one of them, if we have the reference to the function ?
If possible, how to accomplish the same in jQuery and also plain JavaScript ?
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.
Yes, but it depends on how the handler was attached in the first place.
If you used
addEventListener, you can unbind usingremoveEventListener.If you used jQuery, you can use
.unbind().If you used
attachEvent, you can usedetachEvent().If you used
onclickor otheronxxxfunctions, you can remove them by assigningnull, f.exelem.onclick = null.