Skip to content Skip to sidebar Skip to footer

I Want Jquery To Stop Snapping My Loading Div Content Into A Weird Position

I have a quick JQuery question (well I'm hoping it's quick anyway!) I've been combing the forums and can't stop the code from snapping to a weird scroll position (I don't want it t

Solution 1:

You should stop the default event from happening (which is following the anchor). You can either do this by calling event.preventDefault() or returning false from the event handler (the latter will also stop propagation, so use with care).

$("a.linkclass").click(function(event) {
    $('.msg_body').fadeOut("slow");
    $($(this).attr("href")).fadeIn("slow");

    event.preventDefault();
});

or

$("a.linkclass").click(function() {
    $('.msg_body').fadeOut("slow");
    $($(this).attr("href")).fadeIn("slow");

    returnfalse;
});

Solution 2:

Add event.preventDefault() to your click handler:

$("a.linkclass").click(function(e) {
    e.preventDefault();

    $('.msg_body').fadeOut("slow");
    $($(this).attr("href")).fadeIn("slow");
});​

The problem comes when you click on your anchor with linkclass class name, your browser starts navigating to the URL which it set in href attribute.

Post a Comment for "I Want Jquery To Stop Snapping My Loading Div Content Into A Weird Position"