Title: MutationObserver
Last modified: February 1, 2025

---

# MutationObserver

 *  [dmbur](https://wordpress.org/support/users/dmbur/)
 * (@dmbur)
 * [1 year, 3 months ago](https://wordpress.org/support/topic/mutationobserver/)
 * Hello!
 * Could you please add the use of MutationObserver to your script. There is a javascript
   code example of how this might look like
 *     ```wp-block-code
       const wpcf7Forms = document.querySelectorAll( '.wpcf7' );    if ( wpcf7Forms.length ) {        for ( const wpcf7Form of wpcf7Forms ) {            init(wpcf7Form);        }    }    const observer = new MutationObserver((mutationList, observer) => {        for (const mutation of mutationList) {            for (let node of mutation.addedNodes) {                if (!(node instanceof HTMLElement)) continue;                const forms = node.querySelectorAll( '.wpcf7' );                if ( forms.length ) {                    for ( const form of forms ) {                        init(form);                    }                }            }        }    });    observer.observe(document.body, {childList: true, subtree: true});
       ```
   
 * This is to make the script apply to dynamically loaded content, such as popups
   created with javascript code and ajax.
 * Also, to be able to use it with ajax content, you need to modify this check in
   the method `\CF7_AntiSpam\Core\CF7_AntiSpam::load_frontend() `
 *     ```wp-block-code
       if ( ! is_admin() || wp_doing_ajax() ) {    //...}
       ```
   
 * Thanks.

Viewing 1 replies (of 1 total)

 *  Plugin Author [Erik](https://wordpress.org/support/users/codekraft/)
 * (@codekraft)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/mutationobserver/#post-18550653)
 * Hi [@dmbur](https://wordpress.org/support/users/dmbur/) sorry for the very late
   reply, 
   I wanted to tell you that I have implemented your proposal, I hope that
   despite the delay it is welcome.I recommend using git for this, it is more suitable
   for proposing code changes, you can find the link to the repo in the plugin readme.

Viewing 1 replies (of 1 total)

The topic ‘MutationObserver’ is closed to new replies.

 * ![](https://ps.w.org/cf7-antispam/assets/icon.svg?rev=2536700)
 * [AntiSpam for Contact Form 7](https://wordpress.org/plugins/cf7-antispam/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cf7-antispam/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cf7-antispam/)
 * [Active Topics](https://wordpress.org/support/plugin/cf7-antispam/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cf7-antispam/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cf7-antispam/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Erik](https://wordpress.org/support/users/codekraft/)
 * Last activity: [10 months, 2 weeks ago](https://wordpress.org/support/topic/mutationobserver/#post-18550653)
 * Status: not resolved