-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
  • 147,333
  • 58
  • 291
  • 367

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
  • 147,333
  • 58
  • 291
  • 367
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,779
  • 5
  • 59
  • 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
  • 47,944
  • 19
  • 150
  • 166
0

you can use

$('a.btn').click(function(){
    //here
}) ;
PSR
  • 39,804
  • 41
  • 111
  • 151
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
  • 36,319
  • 9
  • 49
  • 62