-1

New to JQuery, I added the following JQuery code below and moved it around in my code and now it won't work I forgot what I did, can someone fix my code by placing the below code in its correct place thanks.

$('a').click(function () {
    $('#changes-saved').remove();
});
    return false; // prevent normal submit
});

JQuery code.

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

    $('a').click(function () {
        $('#changes-saved').remove();
    });
        return false; // prevent normal submit
    });
});

3 Answers 3

1

It looks like an extra paste resulting in an extra return and closing block, just remove this at the end:

    return false; // prevent normal submit
});
Sign up to request clarification or add additional context in comments.

Comments

0

To prevent <a> from propagating in the browser.

$('a').click(function (event) {
    if (!event) event = window.event;
    if (event.preventDefault)
       event.preventDefault();
    else
       event.returnValue = false;


    $('#changes-saved').remove();

    //In case the event propagation didn't work....(mostly dumb IE)
    return false; // prevent normal submit
});

From your code, just fix

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

Comments

0

Is this what you wanted? Had an extra )}; at the end and return false; was not inside the click event handler function.

$(function() {
    $('#changes-saved').hide();

    $('.save-button').click(function() {
        $.post(
            $('#contact-form').attr('action'), 
            $('#contact-form').serialize(), 
            function(html) {
                $('div.contact-info-form').html(html);
                $('#changes-saved').append('Changes saved!')
                    .show().pause(1000).hide();
            }
        );

        return false; // prevent normal submit
    });

    $('a').click(function () {
        $('#changes-saved').remove();

        return false; // prevent normal submit
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.