Any difference b/w jQuery and DOM focus() methods?
HTML
<div>
<button id="first">Click to focus</button>
<input placeholder="Focus me, Seymour" />
</div>
<div>
<button id="second">Click to focus</button>
<input placeholder="Focus me, Seymour" />
</div>
<div>
<a href="http://google.com/">Go!</a>
</div>
JavaScript
$(function () {
// So, I guess I was wrong about focus(). In an isolated context, it works
// exactly as expected. All I know is that in the particular context of the
// app I was working on, running .focus() on a jQuery selector (containing
// one element) did nothing, but throwing in a .get(0) right before it did
// the trick. This happened in Chrome, on a fairly dynamic page. There could
// have been something I didn't isolate, or hey, maybe I found a bug in the
// WebKit Inspector. Wouldn't be the first time.
// My original theory on why that happened stemmed from prior experience
// working with jQuery and triggering browser events, as exemplified by the
// link I added at the bottom. One would expect that a call to .click() (no
// parameters) would actually simulate a person clicking the link, in which
// case the page would navigate to Google. However, all that happens is that
// jQuery triggers any attached event handlers. This is still a fundamental
// WTF.
// Btw, why do you use delegate() in a non-dynamic context?
$('#first').bind('click', function() {
$(this).siblings('input').get(0).focus();
});
$('#second').bind('click', function() {
$(this).siblings('input').focus();
});
$('a:first').click(function() { alert("Theoretical click!"); });
$('a:first').click();
});