JQuery does not execute on $(document).change()

后端 未结 3 1636
生来不讨喜
生来不讨喜 2020-12-06 02:18

I need to make some JQuery execute when the page/document has changed - in this case, when a div with a specific CSS class is displayed.

I have the following JQuery

3条回答
  •  情书的邮戳
    2020-12-06 03:07

    Change is only for input, textarea or select elements. Instead you need to bind a function to the DOMSubtreeModified mutation event:

    $(document).bind('DOMSubtreeModified', function () {
       if ($('.validation_errors').length) {
           alert("test");
       }
    });
    

    EDIT: If your target browsers support it, you should use a MutationObserver instead.

提交回复
热议问题