簡體   English   中英

jQuery追加到同級div

[英]jQuery append to a sibling div

我有以下代碼,使用jquery將元素移動到另一個元素內,但我只需要定位作為元素同級的包裝器而不是所有包裝器。

$('.add_to_cart_button').appendTo('.product-box-image-wrapper');

這是標記:

<li class="post-2045 product type-product status-publish has-post-thumbnail product_cat-accessories product_cat-designer-boots product_cat-footwear product_cat-shorts product_tag-boots product_tag-deluxe last instock featured shipping-taxable purchasable product-type-simple">
<a href="http://localhost:8888/majestica/product/evening-black-night-skirt/" class="woocommerce-LoopProduct-link woocommerce-loop-product__link"><div class="product-box-image-wrapper"><img width="300" height="375" src="http://localhost:8888/majestica/wp-content/uploads/2018/08/kristina-dam-studio-aw17-collection-9-300x375.jpg" class="attachment-woocommerce_thumbnail size-woocommerce_thumbnail wp-post-image" alt=""></div><h2 class="woocommerce-loop-product__title">Evening Black Night Skirt</h2>
<span class="price"><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">£</span>550.00</span></span>

有任何想法嗎 ?

謝謝。

一種選擇是:

$('.add_to_cart_button').each(function() {
   $(this).prev('a.woocommerce-LoopProduct-link').children('.product-box-image-wrapper').append(this);
});

效率較低的選項是:

$(this).closest('li').find('.product-box-image-wrapper').append(this);   

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM