Hi!
I have made a function which does some manipulation to DOM, it’s going to be tied to if statement with a breakPoint.matches.
when the breakpoint gets triggered once again, for example when going back to desktop resolution, I need all DOM elements on their initial locations.
What’s the best way to do this?
function repositionHighwaySelectorForMobile() {
if (breakPoint.matches) {
const highwayPicSelector = document.querySelector(
".highway__arrows_container"
);
const mobileTitleAndSelectorWrapper = document.createElement("div");
const highwaySection = document.querySelector(".highway");
const highwayTitle = document.querySelector(".highway__title");
const highwayText = document.querySelector(".highway__text");
const highwayArrowLeft = document.querySelector(".highway__arrow-left");
const highwayArrowRight = document.querySelector(".highway__arrow-right");
const highwayArrowLeftContainer = document.querySelector(
".highway__slider-button-left"
);
const highwayArrowRightContainer = document.querySelector(
".highway__slider-button-right"
);
mobileTitleAndSelectorWrapper.classList.add(
"highway__title-and-selector-wrapper"
);
highwaySection.prepend(mobileTitleAndSelectorWrapper);
mobileTitleAndSelectorWrapper.appendChild(highwayTitle);
mobileTitleAndSelectorWrapper.appendChild(highwayPicSelector);
mobileTitleAndSelectorWrapper.style.display = "flex";
mobileTitleAndSelectorWrapper.style.flexDirection = "row";
mobileTitleAndSelectorWrapper.style.justifyContent = "space-between";
mobileTitleAndSelectorWrapper.style.alignItems = "center";
mobileTitleAndSelectorWrapper.style.border = "1px solid red";
highwayArrowLeft.src = "./images/small-arrow-left.svg";
highwayArrowRight.src = "./images/small-arrow-right.svg";
highwayArrowLeftContainer.style.width = "24px";
highwayArrowLeftContainer.style.height = "24px";
highwayArrowRightContainer.style.width = "24px";
highwayArrowRightContainer.style.height = "24px";
} else {
???
}
}