Hi!
this function is intended to reposition some elements in DOM each time when max-width passes specific px point.
It seems to me that it works only once. What’s the problem?
let breakPoint = window.matchMedia("(max-width: 1220px)");
const primarySection = document.querySelector(".primary");
const primaryTitle = document.querySelector(".primary__title");
const primaryTextContainer = document.querySelector(".primary__text-container");
function mobileTitleReposition(a, b, c) {
if (breakPoint.matches === "true") {
a.appendChild(b);
console.log("appended");
} else if (breakPoint.matches === "false") {
c.insertBefore(b, c.firstChild);
console.log("inserted");
}
}
breakPoint.addEventListener(
"change",
mobileTitleReposition(primarySection, primaryTitle, primaryTextContainer)
);