Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
Cómo hacer una larga lista de parámetros en la función jQuery

Tengo una larga lista de parámetros que debo pasar a una función jQuery .removeClass .

¿Cómo los agrego todos en un paréntesis separados por comas? Actualmente se ve así...

 $("#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"); });

Pero quiero que se vea así:

 $("#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"); });

Pero eso da como resultado un error unterminated string literal .

Intenté con la barra invertida para escapar de las nuevas líneas, pero eso tampoco funciona.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Necesita literales de plantilla aquí si desea dividir la cadena y eso le permite formatear la lista

También te perdiste una coma

 $("#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"); });

o programarlo

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

En realidad, escapar de la nueva línea DEBERÍA funcionar, pero los literales de la plantilla son más bonitos

 $("#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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!