Custom jQuery not working on Wordpress Ninja Forms plugin

后端 未结 2 1736
野趣味
野趣味 2021-02-08 23:43

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-09 00:02

    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
    

提交回复
热议问题