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

186
Views
¿Una forma más limpia de seleccionar por múltiples valores de atributos posibles?

¿Existe la posibilidad en jQuery de seleccionar por múltiples valores de atributos posibles sin tener que usar una lista de selectores separados por comas?

Así que en lugar de:

 #list1 > option[value="1"], #list1 > option[value="2"], etc

Algo como:

 #list1 > option[value="1"|value="2"], etc
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

No que yo sepa. La forma más limpia que se me ocurre de hacer esto es seleccionar primero usando los elementos comunes en todos los elementos, luego simplemente .find() o .filter() los valores OR.

Algo como

 $('#list1 > option[value]') .filter('[value="1"],[value="2"]') ;
over 4 years ago · Santiago Trujillo Report

0

Puede hacer una función jQuery personalizada como esta:

 $.fn.filterAttrVals = function (attr, vals) { var filter = '[' + attr + '="' + vals.split(',').join('"],[' + attr + '="') + '"]'; return this.filter(filter); };

Para su ejemplo, podría usarlo de la siguiente manera:

 $('#list1 > option').filterAttrVals('value','1,2');
over 4 years ago · Santiago Trujillo Report

0

Puedes hacerlo

 var valuesNeeded = [1,2,etc]; $('#list1 > option').filter(function( index ) { return valuesNeeded.indexOf($(this).attr('value')) != -1; });
over 4 years ago · Santiago Trujillo 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!