Run JS based on screen width

<script>
function myFunction(x) {
if (x.matches) { // If media query matches
$('.p-detail').prepend( $('.p-detail-inner-header') );
} else {
$('.p-detail').prepend( $('.xxxp-detail-inner-header') );  // ISem dej něco jinyho
}
}

var x = window.matchMedia("(max-width: 768px)")
myFunction(x) // Call listener function at run time
x.addListener(myFunction) // Attach listener function on state changes
</script>