120 0 0 0
Last Updated : 2021-01-18 09:36:24
In this class, we will have a helper class that will allow us to do the following: clear event listener from an element. move an element to another location ..etc
class DOMHelper {
static clearEventListener(element) {
const clonedElement = element.cloneNode(true);
element.replaceWith(clonedElement);
return clonedElement;
}
static moveElement(elementId, newDestinationSelector) {
const element = document.getElementById(elementId);
const destinationElement = document.querySelector(newDestinationSelector);
destinationElement.append(element);
}
}
static moveElement(elementId, newDestinationSelector) {
const element = document.getElementById(elementId); //Get old element
const destinationElement = document.querySelector(newDestinationSelector); //Get destination element
destinationElement.append(element);
}
static clearEventListener(element) {
const clonedElement = element.cloneNode(true); //Clone the element
element.replaceWith(clonedElement); //Replace itself with the cloned one
return clonedElement;
}