I'm struggling to uncover what the problem is with this jQuery code. I'm trying to move a couple of elements from one div into another. Depending on the width of the screen. The code works on page load, but not when I resize.
var domWidth = $(window).width();
//Move around page elements
function moveElements() {
var pageTitle = $('.page-title'),
actionAlert = $('.action-alert'),
banner = $("#banner>.container"),
header = $("header>.container"),
mainContent = $(".main-content");
if (domWidth < 1024) {
pageTitle.prependTo(mainContent);
actionAlert.appendTo(header);
} else {
pageTitle.appendTo(banner);
actionAlert.prependTo(banner);
}
}
$(document).ready(function() {
moveElements();
$(window).resize(function() {
moveElements();
});
});