jQuery: move window viewport to show freshly toggled element

Posted by k00k on Stack Overflow See other posts from Stack Overflow or by k00k
Published on 2010-02-24T20:33:43Z Indexed on 2010/05/13 23:24 UTC
Read the original article Hit count: 230

Filed under:
|
|
|
|

I have a simple bit of jQuery in doc ready which toggles a div containing a textarea:

$('div#addnote-area').hide(); // hide the div
$('a#addnote-link').click(function() { // click event listener on link
     $('div#addnote-area').toggle(); // toggle the hidden div 
});

The toggle works fine when clicking the link. The problem I'm having is that if div#addnote-area is below the browser's current viewport, it remains there when it's shown. I'd like the user's cursor to go to the textarea and for the whole textarea to be viewable in the window.

Click here to see an image for more context

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about toggle