title: How to move child element from one parent to another using jQuery
body: <p>I am using the jQuery <a href="http://datatables.net/" rel="noreferrer">DataTables</a> plugin. I would like to move the search box (.dataTables_filter) and number of records to display dropdown (.dataTables_length) from their parent element (.dataTables_wrapper) to another div on my page without losing any registered javascript behavior. For instance the search box has a function attached to the 'keyup' event and I want to keep that intact.</p>
  
  <p>The DOM looks like this:</p>
  
  <pre><code>&lt;body&gt;
  &lt;div id="parent1"&gt;
    &lt;div class="dataTables_wrapper" id="table1_wrapper"&gt;
      &lt;div class="dataTables_length" id="table1_length"&gt;
        &lt;select size="1" name="table1_length"&gt;
          &lt;option value="10"&gt;10&lt;/option&gt;
          &lt;option value="25"&gt;25&lt;/option&gt;
          &lt;option value="50"&gt;50&lt;/option&gt;
          &lt;option value="100"&gt;100&lt;/option&gt;
        &lt;/select&gt;
      &lt;/div&gt;
      &lt;div class="dataTables_filter" id="table1_filter"&gt;
        &lt;input type="text" class="search"&gt;
      &lt;/div&gt;
      &lt;table id="table1"&gt;
      ...
      &lt;/table&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="parent2"&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href="#"&gt;Link A&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;Link B&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;Link C&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>This is what I would like the DOM to look like after the move:</p>
  
  <pre><code>&lt;body&gt;
  &lt;div id="parent1"&gt;
    &lt;div class="dataTables_wrapper" id="table1_wrapper"&gt;
      &lt;table id="table1"&gt;
      ...
      &lt;/table&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="parent2"&gt;
    &lt;div class="dataTables_filter" id="table1_filter"&gt;
      &lt;input type="text" class="search"&gt;
    &lt;/div&gt;
    &lt;div class="dataTables_length" id="table1_length"&gt;
      &lt;select size="1" name="table1_length"&gt;
        &lt;option value="10"&gt;10&lt;/option&gt;
        &lt;option value="25"&gt;25&lt;/option&gt;
        &lt;option value="50"&gt;50&lt;/option&gt;
        &lt;option value="100"&gt;100&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href="#"&gt;Link A&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;Link B&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#"&gt;Link C&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>I've been looking at the .append(), .appendTo(), .prepend() and .prependTo() functions but haven't had any luck with these in practice. I've also looked at the .parent() and .parents() functions, but can't seem to code a workable solution. I have also considered changing the CSS so that the elements are absolutely positioned - but to be frank the page is setup with fluid elements all over, and I really want these elements to be floated in their new parents.</p>
  
  <p>Any help with this is much appreciated.</p>