Single event handler for four button clicks

Since you are using jquery, you don’t need the onclick attribute, just add a class that is similar for all buttons. And DO NOT forget to add the js file of jquery above all js files

$('.someClass').click(function() {
  alert($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input class="someClass" type="button" value="one"><br>
<input class="someClass" type="button" value="two"><br>
<input class="someClass" type="button" value="three"><br>
<input class="someClass" type="button" value="four"><br>

Browse More Popular Posts

Leave a Comment