How can i check if a JavaScript-Eventhandler has been set?

前端 未结 3 1891
别跟我提以往
别跟我提以往 2020-12-14 18:54

I\'ve got a JavaScript-function that sets the \"onclick\"-event of some HTML-Nodes - even if that \"onclick\"-event has been set before.

How can i check if that ev

3条回答
  •  既然无缘
    2020-12-14 19:36

    Check, like this:

    if(typeof someNode.onclick == "function") {
       // someNode has an event handler already set for the onclick event...
    }
    

    By the way, if you are using a library, you should say so - if you are, it might be easier/cleaner and would differ based on which library you are using...

提交回复
热议问题