addEventListener on class

admin

Administrator
Staff member
I need to use
Code:
getElementsByClassName
because I have several same buttons etc.
I work on a wordpress loop that displays a button for each new article, and a registration form must appear on each event when we click on the button.
When I click on the button, I want the form to be displayed and the button to be hidden.
Someone can help me ?

Sorry if there are mistakes, I am French.

Code:
var bouton = document.getElementsByClassName('btn_inscription');
var formulaire = document.getElementsByClassName('formulaire');

   var MyFonction = function{
       formulaire.style.display = 'block';
       bouton.style.display ='none';
   }

   for (var i = 0; i < bouton.length; i++) {

        bouton[i].addEventListener('click', MyFonction);
   }