Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Перемещение элемента (https://javascript.ru/forum/jquery/78005-peremeshhenie-ehlementa.html)

face2005 12.07.2019 14:53

Перемещение элемента
 
Подскажите как правильно переместить элемент в пределах одного блока, а то все в кучу сбивается. Нужно span.price переместить в .blockBotton

jQuery('span.price').prependTo('.blockBotton');


<div class="product-info">
		
	<div class="wrap-price"><span class="price">$200</span></div>
    <div class="blockBotton"></div>

</div>

<div class="product-info">
		
	<div class="wrap-price"><span class="price">$300</span></div>
    <div class="blockBotton"></div>

</div>

<div class="product-info">
		
	<div class="wrap-price"><span class="price">$250</span></div>
    <div class="blockBotton"></div>

</div>

рони 12.07.2019 14:54

face2005,
циклом по product-info

рони 12.07.2019 15:03

face2005,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
  </style>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

  <script>
jQuery(function() {
     jQuery(".product-info").each((i,d) => jQuery('span.price',d).prependTo(jQuery('.blockBotton', d)))
});
  </script>
</head>

<body>
<div class="product-info">

	<div class="wrap-price"><span class="price">$200</span></div>
    <div class="blockBotton"></div>

</div>

<div class="product-info">

	<div class="wrap-price"><span class="price">$300</span></div>
    <div class="blockBotton"></div>

</div>

<div class="product-info">

	<div class="wrap-price"><span class="price">$250</span></div>
    <div class="blockBotton"></div>

</div>

</body>
</html>

face2005 12.07.2019 15:09

Спасибо большое!

laimas 12.07.2019 15:27

Цитата:

Сообщение от рони
циклом по product-info

Да можно и сами span:

$('span.price').each(function() {
        $(this).parent().next().append(this)
    })


Часовой пояс GMT +3, время: 10:26.