Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
Replace selector with array item

I would like to archive that I have an Array, with 3-4 Items and then I want to itterate throw all of them and change the selector in the function with the items of the array.

let items = ['Name','Person,'New']

then my function

$('.btn').on("click", function(){do smth});

and then the foreach .btn should be like name or person, and I want maybe to add late more Items to the array. How should I do it?

for 3 functions

$('.name .btn').on("click", function()){do smth.})

$('.name .test').on("click", function()){do smth.})

$('.name .dosmth').on("click", function()){do smth.})

Name should be replaced with item of the array

I want unique function for the elements

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Try this:

let items = ['name', 'person', 'new']
let elements = [{
    name: 'btn',
    callback: () => {
      // do something
    }
  },
  {
    name: 'test',
    callback: () => {
      // do something
    }
  },
  {
    name: 'dosmth',
    callback: () => {
      // do something
    }
  }
]
items.forEach(item =>
  elements.forEach(element => $(`.${item} .${element.name}`).on("click", element.callback()))
)
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda