Skip to content
HomeExamplesDynamic content

Interaction · Practical

Wait for content that arrives later

Keep a product tour moving while an interface loads data, then anchor the next step as soon as its target appears.

sitetourkit 0.7.1waitForTarget · advanceOn

Loading the interactive example…

Make it yours

Download HTML
import { createTour } from "sitetourkit";
import "sitetourkit/styles.css";
let tour;
let loading;
const status = document.querySelector("#demo-status");
const container = document.querySelector("#report-container");
const load = document.querySelector("#load-report");
load.onclick = () => {
    clearTimeout(loading);
    load.disabled = true;
    container.textContent = "Loading the report…";
    loading = setTimeout(() => {
        const panel = document.createElement("section");
        panel.id = "loaded-report";
        panel.className = "metric-card";
        panel.textContent = "Monthly revenue: $24,840 · Up 18%";
        container.replaceChildren(panel);
    }, 900);
};
document.querySelector("#run-demo").onclick = async () => {
    tour?.destroy();
    clearTimeout(loading);
    load.disabled = false;
    container.textContent = "Your report will appear here.";
    tour = createTour({
        progress: true,
        waitForTarget: { timeoutMs: 5000, onTimeout: "float" },
        steps: [
            {
                target: "#load-report",
                title: "Load the report",
                content: "Select the button. The report takes a moment to arrive.",
                advanceOn: true,
            },
            {
                target: "#loaded-report",
                title: "Your report is ready",
                content: "This step waited for its target instead of failing when the page changed.",
            },
        ],
    });
    tour.on("stepChange", ({ index }) => {
        status.textContent = `Step ${index + 1} of 2`;
    });
    tour.on("complete", () => {
        status.textContent = "Dynamic tour complete. Reset to load the report again.";
    });
    await tour.start();
};
document.querySelector("#reset-demo").onclick = () => {
    tour?.destroy();
    clearTimeout(loading);
    load.disabled = false;
    container.textContent = "Your report will appear here.";
    status.textContent = "Ready to explore. Select Run example.";
};
window.addEventListener("pagehide", () => {
    tour?.destroy();
    clearTimeout(loading);
});
Install sitetourkit, then use this with the example markup.

Handle a target that does not exist yet ​

The first step highlights a report-loading button. Selecting it starts a short simulated load. The next step waits for the report card to appear and then anchors to it, without a manual positioning loop.

Run the example, select Load this month's report, and watch the second step attach to the new card. Reset removes the loaded report so you can try again.

Set a bounded wait ​

waitForTarget sets a timeout and a fallback for a target that never arrives. This example waits up to five seconds and uses a floating step on timeout. Choose a fallback that fits the task: explain the missing UI, skip an optional step, or finish the tour.

The simulated load uses a timer so the example is deterministic and makes no external data request. In your application, the target can arrive after a fetch, route change or component render.

When adapting this example ​

  • Start navigation or loading from your application's own handler.
  • Give the arriving element a stable selector.
  • Cancel pending demo work when resetting or leaving the page.
  • Show real loading and error feedback independently of the tour.