Skip to main content

api.detach()

Description​

Allows removing/detaching event handlers

Usage​

api.detach(tag: number | string ): void;

Parameters​

  • tag - (required) the name of the action tag

Example​

In the example below we add an object with the tag property to the api.on() handler, and then we use the api.detach() method to stop logging the select-slot event.

const widget = new booking.Booking("#root", {
data,
//other configuration parameters
});

// add handler
if (widget.api) {
widget.api.on(
"select-slot",
({ id }) => {
console.log("Selected: " + id);
},
{ tag: "track" }
);
}

// detach handler
function stop() {
widget.api.detach("track");
}

const button = document.createElement("button");

button.addEventListener("click", stop);
button.textContent = "Stop logging";

document.body.appendChild(button);