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

116
Visualizações
How to do long list of parameters in jQuery function

I have a long list of parameters I have to pass into a jQuery .removeClass function.

How do I add them all into one parenthesis separated by commas? Currently it looks like this...

     $("#bottom-nfl").click(function(){
        $("#bottom-mlb i, #bottom-mlb small").removeClass("orange");
        $("#bottom-nba i, #bottom-nba small").removeClass("orange");
        $("#bottom-ncaab i, #bottom-ncaab small").removeClass("orange");
        $("#bottom-profile i, #bottom-profile small").removeClass("orange");
    });

But I want it to look like this:

     $("#bottom-nfl").click(function(){
        $("#bottom-mlb i, #bottom-mlb small,
        #bottom-nba i, #bottom-nba small,
        #bottom-ncaab i, #bottom-ncaab small
        #bottom-profile i, #bottom-profile small").removeClass("orange");
    }); 

But that resultes in unterminated string literal error.

I tried with the backslash to escape the newlines but that doesn't work either

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need template literals here if you want to split the string and that allows you to format the list

Also you missed a comma

 $("#bottom-nfl").on("click", function(){
    $(`#bottom-mlb     i, #bottom-mlb     small,
       #bottom-nba     i, #bottom-nba     small,
       #bottom-ncaab   i, #bottom-ncaab   small,
       #bottom-profile i, #bottom-profile small`).removeClass("orange");
}); 

or program it

$("#bottom-nfl").on("click", function(){
  ["mlb","nba","ncaab","ncaab","profile"]
    .forEach(cls => $(`#bottom-${cls} i, #bottom-${cls} small`).removeClass("orange"));
}); 

Actually escaping the newline SHOULD work, but the template literals are prettier

 $("#bottom-nfl").on("click", function(){
    $("#bottom-mlb     i, #bottom-mlb     small,\
       #bottom-nba     i, #bottom-nba     small,\
       #bottom-ncaab   i, #bottom-ncaab   small,\
       #bottom-profile i, #bottom-profile small").removeClass("orange");
}); 
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