jquery - Append multiple divs to new location (using .prev) -


basically need move links in selection of divs inside div.item

<div class="item">   <div class="inner">     <a class="link">hello</a>   </div> </div> <div class="item">   <div class="inner">     <a class="link">hello</a>   </div> </div> 

ive been playing ab out following script cant seem nail it

  $( ".link" ).each(function(){     var prevbox = $(this).prev('.item');     $(this).appendto(prevbox);   }); 

$(".link").each(function() {    var prevbox = $(this).closest('.item');    $(this).appendto(prevbox);  });    console.log($('.item')[0].outerhtml)
.inner {    background-color: green  }  .link {    background-color: yellow  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div class="item">    <div class="inner">w      <a class="link">hello</a>    </div>  </div>  <div class="item">    <div class="inner">e      <a class="link">hello</a>    </div>  </div>

you want .closest('.item')


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -