---
title: "Change div order to suite responsive viewport"  
description: "Change div order to suite responsive viewport"  
author: "Anonymous User"  
published: 2014-12-31  
updated: 2014-12-31  
canonical: https://www.mindstick.com/forum/12831/change-div-order-to-suite-responsive-viewport  
category: "jquery"  
tags: ["jquery", "html", "responsive design", "css"]  
reading_time: 1 minute  

---

# Change div order to suite responsive viewport

Im using the [script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line) below to change the [order](https://www.mindstick.com/articles/12276/how-timely-order-deliveries-can-improve-customer-experience) of two divs - my [document](https://www.mindstick.com/articles/328642/what-to-consider-while-choosing-a-software-documentation-tool)'s [html](https://www.mindstick.com/articles/1530/design-a-simple-stylish-calculator-using-html-css-and-javascript) has the div [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) "imagepanel ip-middle" preceeding the div class "bgimagescale image2". When viewing on a viewport smaller than 768px wide - I want the divs reversed. The script below does not [reverse](https://www.mindstick.com/blog/63740/what-are-the-most-effective-and-safest-thanks-to-reverse-erectile-dysfunction) the divs on [page load](https://www.mindstick.com/articles/12909/how-to-open-first-time-popup-on-page-load-in-website). Only on resize - as I guess the script indicates!: .bind("resize", listenWidth). I have been unable to locate the [right](https://www.mindstick.com/articles/12766/check-whether-you-are-doing-digital-transformation-right-or-not) way to change the order of the divs using jquery on page load [as well as](https://www.mindstick.com/interview/2481/can-you-write-a-java-class-that-could-be-used-both-as-an-applet-as-well-as-an-application) resize. Many thanks.

```
<script type="text/javascript">jQuery(document).load($(window).bind("resize", listenWidth));function listenWidth( e ) {    if($(window).width()<767)    {        $("div.imagepanel.ip-middle").remove().insertAfter($("div.bgimagescale.image2"));    } else {        $("div.imagepanel.ip-middle").remove().insertBefore($("div.bgimagescale.image2"));    }}</script>
```

## Replies

### Reply by Anonymous User

Use load and resize together, something like this:

$(window).on("load resize",function(e){


---

Original Source: https://www.mindstick.com/forum/12831/change-div-order-to-suite-responsive-viewport

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
