Using appendTo on smaller devices to move div?

Is it possible to wrap something like the code below into a media-querie or something, so that the element only switches place on say devices under 767px width?


I feel this would be a better way than having two different elements and having to use display: none/block on different devices to hide and show them?

I don’t think you can combine JS and media queries in this way.
You can however, just check the viewport width before appending the element.