Created
November 3, 2022 00:02
-
-
Save corypina/8a732660fe8db46e525c9c41ff2e5b82 to your computer and use it in GitHub Desktop.
Move an element from one place to another based on browser/device width
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let breakPoint = 768 | |
let moveThis = document.querySelector('.nodeToMove') | |
let newParent = document.querySelector('.newParentNode') | |
let origin = document.querySelector('.originalParentNode') | |
const moveTheNode = () => { | |
let viewportWidth = window.innerWidth || document.documentElement.clientWidth; | |
if (viewportWidth < breakPoint) { | |
newParent.after(moveThis) | |
} else { | |
origin.prepend(moveThis) | |
} | |
} | |
window.addEventListener('resize', moveTheNode); | |
window.onload = moveTheNode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment