I have a link button that I want to change it onclick
callback function when clicked:
I am using .attr()
to change the onclick
event but it simply doesn't work.
$('#' + test).text('Unlike');
$('#' + test).attr("onclick", "return deleteLikeComment('"
+ CommentsWrapper + "','" + activityID + "', '" + test + "');");
But it simply doesn't work.
I just want to switch the callback method when the link is clicked.
Why are you attaching the event with an attr?
Why not just do like so:
$('#' + test).bind("click", function()
{
//functionality that you were trying to add using attr can now go inside here.
});
$('#' + test).click(function() {
return deleteLikeComment(...);
});
Use "click()" instead of attr()
If you want to switch the callback method every time the link is clicked, use .toggle()
. It alternates between the two provided functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With