how to detect which button is clicked using jQuery
<div id="dBlock">
 <div id="dCalc">
  <input id="firstNumber" type="text" maxlength="3" />
  <input id="secondNumber" type="text" maxlength="3" />
  <input id="btn1" type="button" value="Add" />
  <input id="btn2" type="button" value="Subtract" />
  <input id="btn3" type="button" value="Multiply" />
  <input id="btn4" type="button" value="Divide" />
 </div>
</div>
Note: above "dCalc" block is added dynamically...
$("input").click(function(e){
    var idClicked = e.target.id;
});
                        $(function() {
    $('input[type="button"]').click(function() { alert('You clicked button with ID:' + this.id); });
});
                        Since the block is added dynamically you could try:
jQuery( document).delegate( "#dCalc input[type='button']", "click",
    function(e){
    var inputId = this.id;
    console.log( inputId );
    }
);
demo http://jsfiddle.net/yDNWc/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With