Move Elements with jQuery

Posted on Oct 03, 2025

by Jimmy


A straightforward way to move elements around with jQuery.

JavaScript
        
            function moveElements() {
    if (window.innerWidth <= 800) {
        window.yourElement = jQuery(".your-element").detach();
        jQuery(".mobile-element-container-here").prepend(window.yourElement); // <-- The element's new home on mobile
    } else {
        window.yourElement = jQuery(".your-element").detach();
        jQuery(".desktop-element-container-here").append(window.yourElement); // <-- Put it back where it belongs on desktop
    }
}
jQuery(window).resize(moveElements);        
    

Back to Snippets