Код: Выделить всё
Код: Выделить всё
function handleScreenSize() {
const isSmall = window.matchMedia("(max-width: 599px)").matches;
const largeDiv = document.getElementById("screenLarge");
const storedlargeDiv = document.getElementById("screenLarge"); //largeDiv;
const smallDiv = document.getElementById("screenSmall");
const storedsmallDiv = document.getElementById("screenSmall"); // smallDiv;
const parentElement = document.body;
if (isSmall) {
// Screen is less than 600px: remove the large div
if (largeDiv) largeDiv.remove();
document.body.appendChild(storedsmallDiv);
} else {
// Screen is 600px or more: remove the small div
if (smallDiv) smallDiv.remove();
document.body.appendChild(storedlargeDiv);
}
}
// Run immediately on page load
handleScreenSize();
// Optional: Run whenever the window is resized
//window.addEventListener("resize", handleScreenSize);
//window.addEventListener('resize', handleScreenSize.bind(this));
window.addEventListener('resize', () => this.handleScreenSize());
Вместо этого я получаю сообщение об ошибке Не удалось выполнить 'appendChild' на 'Node': параметр 1 не относится к типу 'Node'.
Означает ли эта ошибка, что storedsmallDiv и storedlargeDiv должны быть Узел? Как мне сделать из них узел?
Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/798 ... arameter-1
Мобильная версия