Get value of the clicked button

You need to use this variable in order to access the clicked button's value.

<script type="text/javascript">
$("button").click(function() {
    var fired_button = $(this).val();
    alert(fired_button);
});
</script>

This would return the value of the button.


UPDATED

Use this instead of button in :

var fired_button = $("button").val(); 

You have to use this to target the current button clicked instead of button that will select all buttons in the DOM, .val() makes it to get the value of the first button.


$("button").click(function() {
    var fired_button = $(this).val();
    alert(fired_button);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="1" name="1" value="1">Button1</button>
<button id="2" name="2" value="2">Button2</button>