title: jQuery detach, prepend and condition
body: <p>I have two div elements that are clickable. When  I click one that contains "1" it will give it class="active", when I click one that contains "2" it will give it class="active" and remove class="active" from the 1st one. Basically it is like switch.</p>
  
  <pre><code>&lt;div class="active"&gt;1&lt;/div&gt;
  &lt;div class=""&gt;2&lt;/div&gt;
  </code></pre>
  
  <p>then this block:</p>
  
  <pre><code>&lt;div class="carousel-inner"&gt;
    &lt;div class="carousel-item " data-id="1" data="carousel-item"&gt;&lt;/div&gt;
    &lt;div class="carousel-item " data-id="2" data="carousel-item"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and after all this code: which is supposed to detach div that don't have data-id of "active" div. When switched, it's supposed to re-attach detached div and detach the second one.</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function(){
      var a = $("div:contains('1')"), 
          b; 
        if (a.hasClass('active')){ 
          b = $("[data-id!='1'][data='carousel-item']").detach(); 
        } 
        else{ 
           $(".carousel-inner").prepend(b);
        } 
  }); 
  &lt;/script&gt;
  </code></pre>
  
  <p>however, it is not working. when I switch (class active moves from one div to another) nothing happens. only first div is detached but on switch it is not reattaching. Any ideas why ? Thanks for any help !</p>
  
  <p>PS: 1. For certain reasons (FU mobirise) I'm not able to manipulate with those two divs with active class(give them onclick() attribute, new class or id and so on).
      2. Sorry for my English.</p>