View Full Version : jQuery keep or set focus on site when using .load

10-28-2009, 11:52 PM
I have a text selected on my site. Then I click a button which uses the load function to show a html form in a dialog. When I start filling out te form, the focus on my selected text is lost (text is deselected). How can I keep the focus or get it back when the dialog closes?

10-29-2009, 01:23 AM
Are you talking about "focus" (the cursor is sitting in the text box ready for entry), or "selected text" (you've dragged your mouse over some text to highlight it)? Two different things and we can manipulate one (focus) via Javascript but not the other (highlight).

10-29-2009, 09:08 AM
I'm talking about selected text but maybe focus might work. How do I do that?

10-29-2009, 06:09 PM
The load function can have a callback function which will be executed once the Ajax call returns from loading an element. You can put any Javascript or jQuery commands in that callback; jQuery has a focus() function you can use.