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>
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>
$('a.btn').click(function(){
//here
});
Note:
<a>
isn't a button.return false
from the callback.data-wap
.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
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">
you can use
$('a.btn').click(function(){
//here
}) ;
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");
});