Have a function for scroll down to input and focus in it?

http://jsfiddle.net/x5cgd16p/

But not want to work? I want to scroll with offset.top and also focus in field?

Any idea?

Thanks!

Open the console. There’s an error in there.

For some reason, the jQuery in your fiddle is rejecting the on() call. Change it to $(...).click(function(event){...} ); and it should work fine. That, or simply switch to a newer version of jQuery in the selector dropdown. 3.x works nicely, tested it with your function as-is.

Thanks! Is scroll now but not focus?

http://jsfiddle.net/x5cgd16p/2/

Uncaught TypeError: asd.focus is not a function

Thanks for help!

Take a look at line six. In line four, you get to the element asd via $("#"+asd) - but line six is throwing an error. See the difference?

So not can be duplicated? Then how can still focus in it? I mean for asd is also scroll and focus? Need to set with a var the first value and then pass to focus?

Thanks!

All I was saying is, in the scrollTop: line, you use the jQuery wrapper on that asd element. In the focus line, however, you don’t.

Consider this, maybe - create a variable with the asd element wrapped in the jQuery object, then use that as a reference in both scrollTop and focus.

http://jsfiddle.net/snowMonkey/qv0o28gh/

1 Like