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

273
Visualizações
Using JavaScript to sort divs based upon content & sorting empty divs to the end

The code below shows my current workings. the commented out line sorts my divs but leaves the empty divs at the top.

the 4 lines above do not make a difference

I think I'm missing something really simple here

//Group 1
    var alphabeticallyOrderedDivs7 = $('.group1').sort(function getSort(a, b) {
        if($(a).find(a).text() === "") return 1;
        if($(b).find(b).text() === "") return -1;
        if($(a).find(a).text() === $(b).find(b).text()) return 0;
        return $(a).find(a).text() < $(b).find(b).text()) ? -1 : 1;
        //return String.prototype.localeCompare.call($(a).text().toLowerCase(), $(b).text().toLowerCase());
    });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can simply do this:

//Group 1
    var alphabeticallyOrderedDivs7 = $('.group1').sort(function getSort(a, b) {
        //Assuming $(a).text() and $(b).text() is the content of the div
        return $(a).text() < $(b).text() ? 1 : $(a).text() > $(b).text() ? -1 : 0;
    });
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