/    Sign up×
Community /Pin to ProfileBookmark

In Javascript, how can I wait for an item to become visible, then disappear?

Hi,
I need to write a pure JavaScript function (no jQuery) that will:

  • 1.

    Wait for a DOC element to become visible.


  • 2.

    Wait for the same element to then become invisible.
    Here is my current attempt:

    var checkVisible = setInterval(function() {
    var el = document.getElementById(‘submitBusy’);
    var style = window.getComputedStyle(el);
    /* See if element is visible. */
    if (style.display !== ‘none’) {
    clearInterval(checkVisible);

    var checkInvisible = setInterval(function() {
    var el = document.getElementById(‘submitBusy’);
    var style = window.getComputedStyle(el);
    /* See if element is visible. */
    if (style.display === ‘none’) {
    clearInterval(checkInvisible);
    }
    }, 50);
    }

  • }, 50);

    On the page, when a certain button is clicked to load a table on the page, the following function is called:

    function searchStart() {
    $(“#submitBusy”).css(“display”, “inline-block”);
    }

    once the page’s contents are pulled from the server, the following is called:

    function searchDone() {
    $(“#submitBusy”).css(“display”, “none”);
    }

    Once the “submitBusy” element is shown and then disappears, I then want to walk through all rows in the newly generated table so I need to know where to put that code.

    Thanks for your help.

    to post a comment
    JavaScript

    2 Comments(s)

    Copy linkTweet thisAlerts:
    @bwclovisMay 29.2020 — Personally, I'd use a css/ js combo for this. On button click, add a show class and then inside the server call ( I'll assume Ajax), Check the element for the class, is it exists, remove.
    Copy linkTweet thisAlerts:
    @edhalsimauthorMay 30.2020 — @bwclovis#1618924 Thanks for the reply. I can't change the code that loads the table. I'm trying to use CefSharp to automate a web page.
    ×

    Success!

    Help @edhalsim spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 3.29,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,

    tipper: Anonymous,
    tipped: article
    amount: 10 SATS,
    )...