title: Swap div in DOM and visually on click using jquery
body: <p>I've a few divs which need to be swapped on click of the corresponding buttons.</p>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;
          &lt;style&gt;
              .box {
                  height: 25%;
                  width: 45%;
                  padding: 1%;
                  margin-left: 1%;    
                  margin-top: 1%;
                  border: 1px solid black;
                  float: left;
  
              }
  
          &lt;/style&gt;
          &lt;script src="css/jquery-3.2.0.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class="container"&gt;
              &lt;div class="box" id="one"&gt;
                  &lt;p&gt;one&lt;/p&gt;
                  &lt;button onclick="moveMe_right()"&gt;Swap with right!&lt;/button&gt;
                  &lt;button onclick="moveMe_down()"&gt;Swap with down!&lt;/button&gt;
              &lt;/div&gt;
  
              &lt;div class="box" id="two"&gt;
                  &lt;p&gt;two&lt;/p&gt;
                  &lt;button onclick="moveMe_left()"&gt;Swap with left!&lt;/button&gt;
                  &lt;button onclick="moveMe_down()"&gt;Swap with down!&lt;/button&gt;
              &lt;/div&gt;
  
              &lt;div class="box" id="three"&gt;
                  &lt;p&gt;three&lt;/p&gt;
                  &lt;button onclick="moveMe_right()"&gt;Swap with right!&lt;/button&gt;
                  &lt;button onclick="moveMe_top()"&gt;Swap with top!&lt;/button&gt;
  
              &lt;/div&gt;
  
              &lt;div class="box" id="four"&gt;
                  &lt;p&gt;four&lt;/p&gt;
                  &lt;button onclick="moveMe_left()"&gt;Swap with left!&lt;/button&gt;
                  &lt;button onclick="moveMe_down()"&gt;Swap with down!&lt;/button&gt;
              &lt;/div&gt;
  
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>For e.g., when I click on Swap with right in div one, it should swap div one and div 2 visually as well as in the DOM it should change to -</p>
  
  <pre><code>&lt;div class="container"&gt;
                  &lt;div class="box" id="two"&gt;
                      &lt;p&gt;two&lt;/p&gt;
                      &lt;button onclick="moveMe_right()"&gt;Swap with right!&lt;/button&gt;
                      &lt;button onclick="moveMe_down()"&gt;Swap with down!&lt;/button&gt;
                  &lt;/div&gt;
  
                  &lt;div class="box" id="one"&gt;
                      &lt;p&gt;one&lt;/p&gt;
                      &lt;button onclick="moveMe_left()"&gt;Swap with left!&lt;/button&gt;
                      &lt;button onclick="moveMe_down()"&gt;Swap with down!&lt;/button&gt;
                  &lt;/div&gt;
  
                  &lt;div class="box" id="three"&gt;
                      &lt;p&gt;three&lt;/p&gt;
                      &lt;button onclick="moveMe_right()"&gt;Swap with right!&lt;/button&gt;
                      &lt;button onclick="moveMe_top()"&gt;Swap with top!&lt;/button&gt;
  
                  &lt;/div&gt;
  
                  &lt;div class="box" id="four"&gt;
                      &lt;p&gt;four&lt;/p&gt;
                      &lt;button onclick="moveMe_left()"&gt;Swap with left!&lt;/button&gt;
                      &lt;button onclick="moveMe_down()"&gt;Swap with down!&lt;/button&gt;
                  &lt;/div&gt;
  
              &lt;/div&gt;
  </code></pre>
  
  <p>Likewise, how would I also achieve the same for swapping with any of the left, top, down divs?</p>