Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6891243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:23:07+00:00 2026-05-27T06:23:07+00:00

I need to ensure that a page stays the way my script describes even

  • 0

I need to ensure that a page stays the way my script describes even after the DOM changes; my script has to handle these changes to the DOM such that my script doesn’t only handle on the initial state.

Is there an event that I can use to handle these DOM changes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:23:07+00:00Added an answer on May 27, 2026 at 6:23 am

    Taking your question in the strictest sense, something like this:

    //--- Narrow the container down AMAP.
    $("YOUR SELECTOR").bind ("DOMSubtreeModified", HandleDOM_ChangeWithDelay);
    
    var zGbl_DOM_ChangeTimer = null;
    
    function HandleDOM_ChangeWithDelay (zEvent) {
        if (typeof zGbl_DOM_ChangeTimer == "number") {
            clearTimeout (zGbl_DOM_ChangeTimer);
            zGbl_DOM_ChangeTimer = '';
        }
        zGbl_DOM_ChangeTimer     = setTimeout (HandleDOM_Change, 333);
    }
    
    function HandleDOM_Change () {
        // YOUR CODE HERE.
    }
    

    Note that you want the intermediate delay function because the changes will come in clusters of 10 to 100’s of events on a site like Youtube or Google.

    You only want to fire on the last event of a cluster — that’s when the change you care about is finished.



    IMPORTANT:

    It’s been a while since I’ve used the DOMSubtreeModified approach, because it performs poorly in practice. So, I forgot I had a utility function for it.

    Also, as Raynos reminds, mutation events are deprecated. So, Firefox may stop supporting these events in some future release.

    One other problem: If your script also changes the nodes in the container you are monitoring, the script can get stuck in an infinite loop/recursion.

    Here is the code to avoid the loop (and that global variable):

    function HandleDOM_Change () {
        // YOUR CODE HERE.
    }
    
    //--- Narrow the container down AMAP.
    fireOnDomChange ('YOUR JQUERY SELECTOR', HandleDOM_Change, 100);
    
    function fireOnDomChange (selector, actionFunction, delay)
    {
        $(selector).bind ('DOMSubtreeModified', fireOnDelay);
    
        function fireOnDelay () {
            if (typeof this.Timer == "number") {
                clearTimeout (this.Timer);
            }
            this.Timer  = setTimeout (  function() { fireActionFunction (); },
                                        delay ? delay : 333
                                     );
        }
    
        function fireActionFunction () {
            $(selector).unbind ('DOMSubtreeModified', fireOnDelay);
            actionFunction ();
            $(selector).bind ('DOMSubtreeModified', fireOnDelay);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to ensure that a input string follows these rules: It should contain
I need to ensure that the user login form for Drupal can not be
I need to ensure that the input value contains at least one dot, so
I need to ensure that a given field does not have more than one
The problem: I need to ensure that a particular directory hierarchy exists in the
I have a page that has three divs one at the top, one at
I have an array full of patterns that I need matched. Any way to
I am creating a Web page that contains the following code. <script> function changeColor(c)
I need to ensure that my webpage is always within an iframe owned by
I need to ensure 2 calls are enlisted in a transaction Sub InsertOrder(order) ...insert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.