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

184
Vistas
How to recognize which button is clicked

I am using wordpress for my blog posts - all posts are fetched on the same page and each post has button, I need to be able to recognise which button of which post was clicked.

I can do it only with hardcoded data, but I am unsuccessful with dynamic ones.

I tried to give a trigger button common class and then detect it in JS.

<div class="row"> 
     <button class="common-button-class">CLICK</button>
</div>

let openButton = document.getElementsByClassName(
    'common-button-class'
);


if (openButton != null) {
            document.querySelector('.common-button-class')
            .addEventListener('click', (event) => {
            // tried detect event id here unsuccessfully 
});
   }

Is there function of how to know which post is being triggered?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Use querySelector instaid of getElementsByClassName

let openButton = document.querySelector('.common-button-class');
openButton.onclick = function() {
    //Your code here
};
about 4 years ago · Juan Pablo Isaza Denunciar

0

you can use jquery in WordPress

first add properties just like data-id and keep post id in it. then :

 $(document).on("click",".common-button-class", function () {
     var clickedBtnID = $(this).data('id'); 
     alert('you clicked on button #' + clickedBtnID);
 });
about 4 years ago · Juan Pablo Isaza 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