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

239
Visualizações
there are 5 "li" element ,how to exchange the first "li" element and the last "li" element?
<pre>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</pre>

there are 5 "li" element ,i want to exchange the first "li" element and the last "li" element? just like this:

<pre>
<ul>
<li>5</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>1</li>
</ul>
</pre>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Question is similar to this one: Changing the order of elements

Easier if you have unique ids, but it is possible with tag names.

(function() {
  let list = document.querySelectorAll("pre > ul > li")
  list[0].parentNode.insertBefore(list[4], list[0])
  list[0].parentNode.append(list[0]);
})();
<pre>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</pre>

about 4 years ago · Juan Pablo Isaza Relatório

0

The naive idea is to get a list of li's, then you pop the first time, then push the same item onto the list, then replace all the children.

Alternatively, Get the content of the first Li, last Li, then replace the values. The first and the second options are semantically different. One copies nodes, while the other merely copies inner text.

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