Forum:WikiaSearch Autofocus

I'm trying to make the search bar automatically focus when something is typed. So I wrote this:

$('*').keypress(function {	$('.WikiaSearch input[type="text"]').focus; } );

But it makes message walls, comments, and any other  or   element pretty much impossible. So I wrote this:

$('input, textarea').unbind;

Only that didn't work. So I tried replacing  with. And that didn't work either, which is why I'm here. Is this solvable, or is it impossible? Thanks in advance. - Sherm / Talk (posted on  12, 2012 at 16:11)


 * Don't use * by itself in jQuery event selectors, ever. The memory usage that causes is insane, you've created something in the order of 10000 copies of that event binding. What you want is to use event bubbling, try this:


 * Most (but not all) events bubble. When you press a key on an element, the event is sent to that element, then it's parent, then that's parent and so on until it reaches the body, document and window. It can be received anywhere along the parent chain unless propagation is stopped. Lunarity 01:43, November 13, 2012 (UTC)


 * Can I have a tl;dr version? :P That is a bit confusing for my simple mind, but I think I understand the gist of how that works. The one thing I don't understand in the code is ; where did that come from!? On the other hand, I completely understand what you meant about , I didn't think about that before. On the practical side of the code, the one unintended difference that I noticed was that the first character that was typed is always missed in the search bar, oddly. Thanks for the help thus far, though, I appreciate it. - Sherm / Talk  (posted on  13, 2012 at 02:39 UTC)