$(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!