unsolved: jQuery: Can you redefine the click function on a button? (unsolved mystery)

I have defined a click function in the document ready

$(“#submit_request_toggle”).click(function() {
$(‘#submit_request’).slideToggle(500);
});

Later, I do an ajax call and I want to be able to redefine the click so that the link doesn’t work anymore (after my ajax call)

$.ajax({
type: “POST”,
url: “index.php”,
data: “action=submit_request&first_name=” + $(‘#submit_request_form input[name=first_name]’).val() + “&last_name=” + $(‘#submit_request_form input[name=last_name]’).val() + “&message=” + $(‘#submit_request_form textarea[name=message]’).val(),
success: function(msg){

$(“#submit_request_toggle”).click(function() { return false; });
$(“#submit_request”).fadeOut(500, function() { $(“#submit_request_response”).html(msg).fadeIn(); } );
}

For some reason, this line:

$(“#submit_request_toggle”).click(function() { return false; });

doesn’t work– the link still shows the hidden div even after I redefine it. Weird.

1 reply on “unsolved: jQuery: Can you redefine the click function on a button? (unsolved mystery)”

The .click(handler) function is just a shortcut for .bind(‘click’, handler) . You can use unbind(‘click’) to remove the click “event” right before binding the new click “event”. (I don’t think it’s actually an event, because when I tried .onclick = undefined, it didn’t work.)

Leave a Reply

OR LOG IN WITH




Your email address will not be published. Required fields are marked *