Reputation: 573
I have anchor link with onclick and href functions. like below code
$("div.actions").append('<a id="excelExport" onClick="callajax();" class="actionButton" alt="Export to Excel" title="Export to Excel" href="partexport" ></a>')
function callajax() {
jQuery.ajax({
url : '<s:url action="partexport"/>',
data : "fters.productNbr" : $("#productsTextArea1").val()} });
}
Callajax is not at all calling when click the anchor link.
Upvotes: 1
Views: 586
Reputation: 4413
There are a coulple things at play here.
http://jsfiddle.net/g30rg3/u5k95/3/
$(document).ready(function(){
$("div.actions").append('<a id="excelExport" class="actionButton" alt="Export to Excel" title="Export to Excel" href="http://www.stackoverflow.com">click me</a>');
$('div.actions').on('click.mylink', '#excelExport',function(e){
e.preventDefault();
callajax();
});
});
function callajax() {
alert('clicked');
}
Upvotes: 1
Reputation: 64526
The click event will be executed first and then depending on the result, the href will be executed. For example returning false
from the click event will prevent the href from being executed.
Upvotes: 0
Reputation: 66663
The click
handler will fire first. Depending on how to process your click, you can control whether the href link action goes through or not.
You can do both - i.e. have your click handler as well as the link action to go through. All you need to do is not return false
or call event.preventDefault()
from your click handler.
Upvotes: 2