JQuery if statements?

Posted by SLAPme on Stack Overflow See other posts from Stack Overflow or by SLAPme
Published on 2010-03-23T05:48:16Z Indexed on 2010/03/23 5:53 UTC
Read the original article Hit count: 143

Filed under:

New to JQuery and was wondering how can I put the following JQuery code in an if statement so that it only runs when the submit button is clicked and does nothing when not clicked I know I'm using the $(".save-button").click(function() is there a way to put it in an if statement?

JQuery code.

$(function() {
    $(".save-button").click(function() {
        $.post($("#contact-form").attr("action"), $("#contact-form").serialize(), function(html) {
            $("div.contact-info-form").html(html);
            $('#changes-saved').append('<li>Changes saved!</li>').show().pause(1000).hide();
        });
        return false; // prevent normal submit
    });
});

© Stack Overflow or respective owner

Related posts about jQuery