How to use the click event for the anchor tag and the tag button simultaneously in jQuery?

advertisements

I'm using jQuery 1.9.1 in my project. I've following HTML :

<button type="button" id="btn_add" class="btn btn-primary">Add</button>
<a class="btn_delete" href="#"><i class="icon-trash"></i></a>

I want to display the same alert message if user clicks on a icon enclosed in anchor tag with class "btn_delete" or click on a button having id "btn_add".

For this I tried following code but it didn't work out for me.

$(document).ready(function() {
  $("button#btn_add.btn_delete").on("click", function(event) {
    event.preventDefault();
    alert("This action has been temporarily disabled!")
  });
});

Can someone please help me in this regard please?

If you want any more information regarding the issue I'm facing please let me know.

Thanks in advance.


   **Approach #1**
   function doSomething(){
    //your code
   }

   $('#btn_add').click(doSomething);
   $('.btn_delete').click(doSomething);

   **Approach #2**
   $("#btn_add,a.btn_delete").on("click", function(event) {
      event.preventDefault();
      alert("This action has been temporarily disabled!")
   });