tags:

views:

60

answers:

2

Hi,

It's hard to describe the whole problem but to make a long story short, I can't use href="...#something" but I need this functionality. Is there a way to replicate it with jquery? So I want to have something like this onclick="$('div#something').jumpThere();" but I don't know the exact name of the function. Could you please let me know whether jquery has such function and if yes, how it is called.

+6  A: 

You don't need jQuery

window.location.hash = '#something';

should do it.

Pointy
What is this... "JavaScript without using jQuery" you talk about? Some kind of black magic?
Matti Virkkunen
@Matti: It's Voodoo, if you're after specifics
Nick Craver
Lol, thanks, it's exactly what I need! With all this fancy jquery stuff I forgot good old JS times :))
Eugene
can I say LOL!!?
Reigel
@Eugene: That virtually doesn't do anything different than a normal `href="#something"`. IMHO you should expand on how your anchors are broken, because I think you are fixing the wrong problem.
RoToRa
I think he meant that he can't (why? don't know) do this with simple `<a href='#something'>click</a>` tags.
Pointy
Yeah true, the stuff inside href simply gets broken. So right now (thanks to the solution offered by Pointy) my code is href="#broken_anchor" onclick="window.location.hash = '#good_anchor';". I do know that this is an extremely dirty fix but I just need a temporarily workaround to save the day :)
Eugene
A: 

Difficult. But i would look into on click, getting the .position() of the element you want to go to. Then setting the window.scrollTop to that value (this will only work in some situations). That would be where I would start: .position() and window.scrollTop

Bob Fincheimer