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

176
Views
¿Cómo usar los selectores jQuery con variables?

He visto muchas preguntas similares, pero ninguna de las respuestas funcionó en mi caso.

Se establece una variable en función del ancho del documento:

 if ($(document).width() < 1400) { var tblProdukty = document.getElementById('tblProdukty1280'); } else { var tblProdukty = document.getElementById('tblProdukty1920'); }

Entonces me gustaría hacer algo como esto: $("#tblProdukty1280 > tbody").empty(); pero con una variable establecida como arriba en algo como esto:

 $("#" + tblProdukty + " > tbody").empty();

o

 $(`${tblProdukty}` + " > tbody").empty();

Probé diferentes combinaciones de concatenación e inyección y no pude resolverlo. Recibí el siguiente mensaje de error: Error no detectado: error de sintaxis, expresión no reconocida: #[objeto HTMLTableElement] > tbody

¿Puede por favor aconsejarme sobre esto?

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

0

Puedes hacerlo de 2 maneras diferentes:

primero, puede usar la variable tblProdukty como referencia al elemento:

 if ($(document).width() < 1400) { var tblProdukty = $("#tblProdukty1280"); } else { var tblProdukty = $("#tblProdukty1920"); }

Entonces úsalo de esta manera:

 tblProdukty.find("tbody").empty();

O puedes hacer algo así:

 if ($(document).width() < 1400) { var tblProdukty = "tblProdukty1280"; } else { var tblProdukty = "tblProdukty1920"; }

Entonces úsalo de esta manera:

 $(`#${tblProdukty}` + " > tbody").empty();
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!