Hello I am new to coding with jquery and I am trying to implement something that switches the tables position in my html when the width of the window changes. I feel like I am missing something or using it incorrectly.

I have the script tag below the tables not sure if that matters. #list1 and #list2 are id’s to <ul>
Given the code snippet that you showed, you’re checking the width of the window a single time, thus only performing the reordering a single time.

I’ve put together a little snippet that should do what you’re wanting, presuming I didn’t misinterpret your post.
I’ve added comments to it as well, in case you weren’t sure about something.

Here’s a link to the [JSFiddle] sandbox where I tried this.
Beautiful this is exactly what I needed. Thank you for your help 🙂
Not sure what your use case here is, but throwing it out there that if it’s just a visual thing, the same could be achieved in css by wrapping the two in a container and using flex-direction:row-reverse (or column-reverse) in a media query.

Of course, you may very well be doing it for other reasons, or be unable to change the markup, but throwing it out there in case anybody stumbles upon this in the future.

source