I have a button
<button onclick="DeletaItem('template','1234')" id="btn">Deletar_func</button>
And the function
function DeletaItem(tipo,id_cripto){
alert(tipo+id_cripto);
alert($(this).attr('id'));
}
Why the second alert is undefined?
The second alert is undefined because this does not refer to the button, it actually refers to the window object.
You need to either send this to the function, change the onclick to the following:
and also change the function as follows:
or leave the onclick as it is and use event.target within the function instead of this.