Question: I have a sliding panel set up on my website.

When it finished animating, I set the hash like so

```
function() {
   window.location.hash = id;
}

```

(this is a callback, and the `id` is assigned earlier).

This works good, to allow the user to bookmark the panel, and also for the non JavaScript version to work.

However, when I update the hash, the browser jumps to the location. I guess this is expected behaviour.

My question is: how can I prevent this? I.e. how can I change the window's hash, but **not** have the browser scroll to the element if the hash exists? Some sort of `event.preventDefault()` sort of thing?

I'm using jQuery 1.4 and the [scrollTo plugin](http://plugins.jquery.com/project/ScrollTo).

Many thanks!

Update
------

Here is the code that changes the panel.

```
$('#something a').click(function(event) {
    event.preventDefault();
    var link = $(this);
    var id = link[0].hash;

    $('#slider').scrollTo(id, 800, {
        onAfter: function() {

            link.parents('li').siblings().removeClass('active');
            link.parent().addClass('active');
            window.location.hash = id;

            }
    });
});

```

Answer: 
Cheap and nasty solution.. Use the ugly #! style.

To set it:

```
window.location.hash = '#!' + id;

```

To read it:

```
id = window.location.hash.replace(/^#!/, '');

```

Since it doesn't match and anchor or id in the page, it won't jump.
Why dont you get the current scroll position, put it in a variable then assign the hash and put the page scroll back to where it was:

```
var yScroll=document.body.scrollTop;
window.location.hash = id;
document.body.scrollTop=yScroll;

```

this should work