Adding onClick event dynamically using jQuery

后端 未结 6 1841
梦毁少年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条回答
  •  旧时难觅i
    2020-11-30 22:41

    You can use the click event and call your function or move your logic into the handler:

    $("#bfCaptchaEntry").click(function(){ myFunction(); });
    

    You can use the click event and set your function as the handler:

    $("#bfCaptchaEntry").click(myFunction);
    

    .click()

    Bind an event handler to the "click" JavaScript event, or trigger that event on an element.

    http://api.jquery.com/click/


    You can use the on event bound to "click" and call your function or move your logic into the handler:

    $("#bfCaptchaEntry").on("click", function(){ myFunction(); });
    

    You can use the on event bound to "click" and set your function as the handler:

    $("#bfCaptchaEntry").on("click", myFunction);
    

    .on()

    Attach an event handler function for one or more events to the selected elements.

    http://api.jquery.com/on/

提交回复
热议问题