Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

384
Visualizações
jQuery().detach().appendTo Duplicating all detached elements

I'm trying to add some extra divs to the build-in blogs "read more" links. I've managed to add all the necessary div but I'm struggling to move the text from where it is into another div. I've managed to move it using:

'''jQuery(".readmore").detach().appendTo('.js-add-btn-assets');'''

But instead of moving the one .readmore element to the .js-add-btn-assets. Its making copies of all of the Read More Links on the page and putting them all under the .js-add-btn-assets so I essentially have 4 .readmore elements for every Read More link.

enter image description here

How do I change this so the .readmore class is only moving to the .js-add-btn-assets within its respected parent class instead of all classes on the page? Like this:

enter image description here

Here all the code I'm currently using

<span class="more-link">
  <a href="#" class="readmore">Continue reading
    <span class="screen-reader-text">Blog Template</span>
  </a>
</span>
var AddButtonWrap = document.querySelectorAll(".more-link");
    for (i = 0; i < AddButtonWrap.length; i++) {
                AddButtonWrap[i].classList.add("dbtb-button-wrap add-dbtb-button-div");
        }
    
var SelectButtonDiv = document.querySelectorAll(".add-dbtb-button-div"); {
    for (i = 0; i < SelectButtonDiv.length; i++) {  
        var dbtbBtnDiv = document.createElement('div');
        dbtbBtnDiv.className = 'dbtb-button js-add-btn-assets';
        SelectButtonDiv[i].appendChild(dbtbBtnDiv);
        }
    }
        
jQuery(".readmore").detach().appendTo('.js-add-btn-assets');
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Do the moves in a third loop. Something like below should work (untested) First detach, then Append.

for (i = 0; i < AddButtonWrap.length; i++)
{
    var readMore = jQuery(AddButtonWrap[i]).find(".readmore").detach();
    readMore.appendTo(jQuery(AddButtonWrap[i]).find(".js-add-btn-assets"));
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda