如何更改选定元素的多个实例的位置

发布于 2024-12-19 18:50:46 字数 2363 浏览 4 评论 0原文

我需要将每个 h3 元素从下面的位置移动到新位置,作为 .summary-inside-wrapper 的第一个子

元素 我尝试过的所有操作都将所有 h3 元素的实例移动到每个摘要中。我只需要移动每个摘要中的原始内容。

<div class="content-main">
   <div class="summary" id="listing_summary_3547">
      <div class="share"></div>
      <div class="summary-inside-wrapper">
         <div class="summary-inside">                <---- TO HERE ---| 
            <div class="left">                                        |
               <div class="title">                                    | 
                  <h3>unique text here 1</h3>      -- MOVE THIS h3 ---|      
                  <p>some other text here</p>
               </div>
            </div>
            <div class="right"></div>
         </div>
      </div>
   </div>
   <div class="summary" id="listing_summary_45741">
      <div class="share"></div>
      <div class="summary-inside-wrapper">
         <div class="summary-inside">                <---- TO HERE ---| 
            <div class="left">                                        |
               <div class="title">                                    | 
                  <h3>unique text here 1</h3>   --and MOVE THIS h3 ---|      
                  <p>some other text here</p>
               </div>
            </div>
            <div class="right"></div>
         </div>
      </div>
   </div>
   <div class="summary" id="listing_summary_6">
      <div class="share"></div>
      <div class="summary-inside-wrapper">
         <div class="summary-inside">                <---- TO HERE ---| 
            <div class="left">                                        |
               <div class="title">                                    | 
                  <h3>unique text here 1</h3>   --and MOVE THIS h3 ---|      
                  <p>some other text here</p>
               </div>
            </div>
            <div class="right"></div>
         </div>
      </div>
   </div>
</div>

我尝试过 insertBefore()、prepend() 等,但没有得到预期的结果。每次我都会在摘要的每个实例中获取每个 h3 的副本。

I need to move the each of the h3 elements from their position below to a new position as first child of .summary-inside-wrapper

Everything I have tried moves an instance of ALL the h3 elements into each summary. I need for only the original within each summary to be moved.

<div class="content-main">
   <div class="summary" id="listing_summary_3547">
      <div class="share"></div>
      <div class="summary-inside-wrapper">
         <div class="summary-inside">                <---- TO HERE ---| 
            <div class="left">                                        |
               <div class="title">                                    | 
                  <h3>unique text here 1</h3>      -- MOVE THIS h3 ---|      
                  <p>some other text here</p>
               </div>
            </div>
            <div class="right"></div>
         </div>
      </div>
   </div>
   <div class="summary" id="listing_summary_45741">
      <div class="share"></div>
      <div class="summary-inside-wrapper">
         <div class="summary-inside">                <---- TO HERE ---| 
            <div class="left">                                        |
               <div class="title">                                    | 
                  <h3>unique text here 1</h3>   --and MOVE THIS h3 ---|      
                  <p>some other text here</p>
               </div>
            </div>
            <div class="right"></div>
         </div>
      </div>
   </div>
   <div class="summary" id="listing_summary_6">
      <div class="share"></div>
      <div class="summary-inside-wrapper">
         <div class="summary-inside">                <---- TO HERE ---| 
            <div class="left">                                        |
               <div class="title">                                    | 
                  <h3>unique text here 1</h3>   --and MOVE THIS h3 ---|      
                  <p>some other text here</p>
               </div>
            </div>
            <div class="right"></div>
         </div>
      </div>
   </div>
</div>

I have tried insertBefore(), prepend() and many more without the desired results. Each time I get copies of EVERY h3 inside each instance of the summary.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

知你几分 2024-12-26 18:50:46

代码:

$(".title h3").each(function()
                    {
                       var item=$(this); 
                       var parentContainer=item.parents(".summary-inside");
                       item.remove();
                       parentContainer.prepend(item);
                    });

这是一个现场演示

Code:

$(".title h3").each(function()
                    {
                       var item=$(this); 
                       var parentContainer=item.parents(".summary-inside");
                       item.remove();
                       parentContainer.prepend(item);
                    });

here is a Live Demo

望笑 2024-12-26 18:50:46

这应该可以解决问题

 $( ".summary-inside-wrapper" ).each(function() {
    $( this ).prepend( $( this ).find( ".title > h3" ).html() );
    $( this ).find( ".title" ).remove();
});  

this should do the trick

 $( ".summary-inside-wrapper" ).each(function() {
    $( this ).prepend( $( this ).find( ".title > h3" ).html() );
    $( this ).find( ".title" ).remove();
});  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文