$(document).ready(function() { $("button").on("click", function() { alert($(this).attr("class")); }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type='button' class='met1' value='vvod' /><br> <input type='button' class='met2' value='vvod' /><br> <input type='button' class='met2' value='vvod' /><br> 

Actually I generate the buttons themselves through php something like: btn1 , btn2 , etc.
In the js file I describe the following thing:

 $(document).ready(function(){ $("button").on("click",function(){ alert($(this).attr("class")); }); }); 

Well, nothing works ... Maybe there is some simple way to make the buttons work (I don’t want to write 10 buttons)?

Well, I wanted to get the class name in order to pull out the number of the button from it and then throw the request into ajax .

Or maybe someone has an idea to get the number of buttons somehow different, I will be grateful for any help, thanks!

  • Everything is working. What does it mean "nothing works"? The little gnome gets out of the computer and says: "Nothing works"? - Igor
  • Well, if everything worked, I would not write here. - vados inferno
  • Create a "non-working" example using the button "Code snippet ..." in the question editor. - Igor

1 answer 1

You have an element called input , and you're looking for $('button') . Need to change either one or the other.

  • 2 o'clock in the morning, I sleep)) thanks, changed to input [type = button], everything worked. - vados inferno