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.
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"); });