Custom jQuery not working on Wordpress Ninja Forms plugin

后端 未结 2 1113
再見小時候
再見小時候 2021-02-08 23:17

I am having some problems when I want to add custom jQuery code that affects the form.

For example when someone clicks an input or radio button another input or element

2条回答
  •  悲哀的现实
    2021-02-08 23:50

    The event isn't registered simply because the elements you're trying to bind the event to do not exist yet at that moment (on document load). Ninja forms loads the form contents asynchronously, so you'll have to wait until the form is fully loaded and then add your event listeners. This works for me:

    var formExists = setInterval(function() {
      if ($(".nf-form-cont").length) {
        // Set your event listeners here, example:
        $("#nf-field-1").click(function(e) {
          console.log("click!");
        }
        clearInterval(formExists);
      }
    }, 100); // check every 100ms
    

提交回复
热议问题