tags:

views:

69

answers:

3

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
    });
});
A: 

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
    });
    });
});
The Elite Gentleman
+1  A: 

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
});
Nick Craver
A: 

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
    });
});
jwwishart