Else statements can't have a condition attached.
else ($(window).width() > 1024) {
$('.div1').insertBefore('.div2');
}
});
has to be
else {
$('.div1').insertBefore('.div2');
}
});
If you wan't to call this during page load, you can put it into a function and call the function both on resize and on page load.