JQuery function when clicking a link

I am trying to call the jquery function when clicking a link without success:

here is my html:

<a href="..." id="removeItem" checkID="12" >Delete</a> <a href="..." id="removeItem" checkID="13" >Delete</a> <a href="..." id="removeItem" checkID="14" >Delete</a> $("#removeItem").click(function(checkID) { return false; var checkID = $(this).attr("checkID"); $("#removeDialog").dialog( { buttons: { "No" : function () { $(this).dialog("destroy"); $('input#CheckName').focus(); }, "Yes": function () { $.ajax({ url: "itemRemoveWS.html?id=checkID", data: { "action" : "remove", "id" : checkID }, success: function (data) { $("#removeDialog").dialog("destroy"); var ang = ''; var obj = $.parseJSON(data); $.each(obj, function() { ang += '<table class="form"><tr><td width="45">' + this["CheckID"] + '</td><td width="140">' + this["Name"] + '</td><td width="95">' + this["CheckNumber"] + '</td><td align="right" width="70">$' + this["Amount"] + '</td><td width="220" style="padding-left: 15px;">' + this["Description"] +'</td><td><a href="#">Delete</a></td></tr></table>'; }); $('#container').html(ang); $("input#Amount").val(''); $("input#CheckName").val(''); $("input#Check_Number").val(''); $("select#Company").val('MMS'); $("th#dept").hide(); $('input#CheckName').focus(); } }); } } }); }); 
+4
source share
4 answers

You have return false; as the first statement in your click event callback function. This means that you are not doing anything.

Put it on the very last line of your logic or better change it to e.preventDefault(); using

 $("#removeItem").click(function(e) {...} 

As a side note, $("#removeItem").click(function(checkID) {} checkID will be a reference to the triggered event here, and not the id attribute of the element.

Again, the ID attribute MUST be unique for each element on each html page.

+7
source

To call a function by reference, use javascript: void (0) as the href, then add your function call to the onclick event of your link:

 <a runat="server" id="myButton" href="javascript:void(0);" onclick="myFunction();" ></a> 
+2
source

Instead of using return false do the following:

 checkID.preventDefault(); 

In addition, you are not allowed to have two elements with the same identifier.

0
source

As fried said, return the lie, probably your problem. Perhaps you meant this:

 checkID.preventDefault(); 
0
source

All Articles