title: Add an element to DIV based on condition
body: <p>I am trying to insert a <code>&lt;table&gt;</code> element inside a <code>&lt;div&gt;</code> at a particular location based on two conditions.</p>
  
  <p>condition 1 : based on the page Num</p>
  
  <p>condition 2 : based on the ordernum.</p>
  
  <p>For example : </p>
  
  <pre><code> &lt;div id="printContainer"&gt;
        &lt;table class="BKG pg1" id="tbl-09-338785" data-ordernum="0"&gt;
        &lt;/table&gt;
        &lt;table class="BKG pg1" id="tbl-09-338786" data-ordernum="1"&gt;
        &lt;/table&gt;
        &lt;table class="BKG pg2" id="tbl-09-338787" data-ordernum="0"&gt;
         &lt;/table&gt;
        &lt;table class="BKG pg2" id="tbl-09-338788" data-ordernum="1"&gt;  
        &lt;/table&gt;
        &lt;table class="BKG pg3" id="tbl-09-338789" data-ordernum="0"&gt;
        &lt;/table&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>If I want to enter </p>
  
  <pre><code>&lt;table class="BKG pg2" id="tbl-09-338790" data-ordernum="5"&gt;
  </code></pre>
  
  <p>inside the <code>div</code> then it should get append to the list in between</p>
  
  <pre><code>&lt;table class="BKG pg2" id="tbl-09-338788" data-ordernum="1"&gt;  and 
  &lt;table class="BKG pg3" id="tbl-09-338789" data-ordernum="0"&gt;
  </code></pre>
  
  <p>Now if I want to enter </p>
  
  <pre><code>&lt;table class="BKG pg2" id="tbl-09-338791" data-ordernum="3"&gt;
  </code></pre>
  
  <p>inside the <code>div</code> then it should get append to the list in between</p>
  
  <pre><code>&lt;table class="BKG pg2" id="tbl-09-338788" data-ordernum="1"&gt;  and 
  &lt;table class="BKG pg2" id="tbl-09-338790" data-ordernum="5"&gt;
  </code></pre>
  
  <p><a href="http://jsfiddle.net/jNDRN/1" rel="nofollow">JsFiddle</a></p>