How to execute a javascript referencing a button ID?

1

I need to execute a javascript, but I would like to do this using the ID of the button that clicked,

Example:

$ (document) .ready (function () {

  $("p").click(function(){
      alert("estou usando o P.");
  });

  $('teste').on('click',function(){
        //eu precisa de alguma coisa assim
         alert("estou usando o id."); 
  });

});

How to use reference id?

In this example only works when using the "P" tag

Thank you

    
asked by anonymous 29.04.2017 / 03:21

1 answer

0
var btn1 = document.querySelector("#mostrarcampo");
btn1.addEventListener('click',function(e){
    document.querySelector("#extratres").style.display = 'block';
 });

This does the same as the excerpt

$('#mostracampo1').on('click',function(){
    //eu precisava de alguma coisa assim
    document.getElementById("extratres").style.display = 'block';  

});

    
29.04.2017 / 03:54