-4

Following is the html code for a button.I need to track this button click.

<div class="abc">
    <a class="btn" data-wap="{"linktype":"xyz"}" href="#content">
</div>
gdoron is supporting Monica
  • 142,542
  • 55
  • 282
  • 355

5 Answers5

3
$('a.btn').click(function(){
    //here
});

Note:

  • <a> isn't a button.
  • If you want to cancel the default behavior and the bubbling return false from the callback.
  • Fix the quotes in the data-wap.
gdoron is supporting Monica
  • 142,542
  • 55
  • 282
  • 355
2

You can just do:

$('.btn').click(function() {
    // Your code here
});

You also need to close the anchor tag using </a>. As suggested by @MichaelWright, you also need to adjust the quotes of your data-wap

Eli
  • 14,673
  • 5
  • 57
  • 77
0

Attach an event to click like this:

$('.btn').click(function () {
    // code here
});

Also your quotes are incorrect which could cause issues for you, use single quotes within the double quotes so it doesn't break them.

<a class="btn" data-wap="{'linktype':'xyz'}" href="#content">
Daniel Imms
  • 45,529
  • 17
  • 143
  • 160
0

you can use

$('a.btn').click(function(){
    //here
}) ;
PSR
  • 38,073
  • 36
  • 106
  • 149
0

try this

HTML

 <div class="abc">
    <a class="btn" data-wap="{'linktype':'xyz'}" href="#content"></a>
 </div>

jquery

$('a.btn').click(function(e){
  e.preventDefault();
  alert("clicked");
});
bipen
  • 35,563
  • 9
  • 45
  • 62