views:

85

answers:

3

as title suggests. id string is passed to view as ViewData variable.

+2  A: 

$('#id')[0].focus() should do it

Rex M
That will trigger the focus event handlers, but it won't actually call the focus() method on the underlying object.
tvanfosson
@tvanfosson you're right, i fixed that.
Rex M
It's weird that the documentation says one thing, but they have an example that does the opposite. In retrospect, I'd say, maybe try the focus() method on the jQuery object itself and see if it works.
tvanfosson
Note: even if it works, it will probably only work for an input element. Not every DOM object supports the focus method.
tvanfosson
@tvanfosson yeah, I've done something like this in the past but now that I've let it sit on my brain for a few minutes I'm not so sure if this was it.
Rex M
fyi couldnt get this to work, but plugin below did.
zsharp
@zsharp glad you got it working! I recommend accepting that answer, then.
Rex M
+3  A: 

Looks like there is a nice plug-in for jQuery available to do just that here: http://flesler.blogspot.com/2007/10/jqueryscrollto.html

Kyle B.
A: 

You could also append the ID to the URL using the hash:

http://www.someurl.com/page.html#the_id
Philipe Fatio
Works if it's an anchor, but not if it is any generic element on the page.
tvanfosson
Presumably this is also on the rendering side which would mean that you'd have to redirect to the new url and process the request again, but this time with the tag.
tvanfosson
anchor like `<a name="test"></a>`? It works with every ID on the page.
Philipe Fatio