Q:

After Javascript confirm dialog, web page goes to top. How to stop this?

I'm using a confirm dialog as a yes/no confirmation on whether to remove a few elements from the page. That part works fine. The problem is that after clicking either 'confirm' or 'cancel' the page scrolls to the top. How can I stop this behavior?
$('.deleter').click(function () {
    if (confirm('Do you want to remove' + $(this).attr('name') + '. This action can not be undone.')) {
        $('.g' + $(this).attr('itemId')).remove();
        $('.' + $(this).attr('itemId')).remove();
    }
});

Failing that, a work around that sets the window back to it's previous space would be fine.
edit: HTML CODE
<a href='#' class='deleter' name='eg' itemId='4'>delete</a>

Thanks for reading

A:

It's actually jumping to the location # (the default behaviour of a).
You need to prevent this default behaviour by preventDefault().
Try this,
$('.deleter').click(function (e) {
    e.preventDefault();
    if (confirm('Do you want to remove' + $(this).attr('name') + '. This action can not be undone.')) {
        $('.g' + $(this).attr('itemId')).remove();
        $('.' + $(this).attr('itemId')).remove();
    }
});

