With jQuery you can just do it:
$('button[type="button"]').on('click', function(){
// e aqui, o this é o botão clicado
var id = this.id;
var classes = this.classList;
});
If you want to do only with native Javascript you can do so:
var botoes = document.querySelectorAll('button[type="button"]');
for (var i = 0; i < botoes.length; i++){
botoes[i].addEventListener('click', function(){
// e aqui, o this é o botão clicado
var id = this.id;
var classes = this.classList;
});
}
Note:
- notice that you have
tupe
instead of type
.
- Remember that Ids must be unique, and classes shared. In your text you say "each has a different class [...] the id is unique", maybe it’s right but the description gives me idea that not