Adding onClick event dynamically using jQuery

后端 未结 6 1831
梦毁少年i
梦毁少年i 2020-11-30 22:24

Due to a plugin being used, I can\'t add the \"onClick\" attribute to the HTML form inputs like usual. A plugin is handling the forms part in my site and it doesn\'t give an

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 22:52

    Try below approach,

    $('#bfCaptchaEntry').on('click', myfunction);
    

    or in case jQuery is not an absolute necessaity then try below,

    document.getElementById('bfCaptchaEntry').onclick = myfunction;
    

    However the above method has few drawbacks as it set onclick as a property rather than being registered as handler...

    Read more on this post https://stackoverflow.com/a/6348597/297641

提交回复
热议问题