> Imagine that you have an array: > > var a = [ 'a', 'b', 'c' ]; > > Now you can call array methods on the array: > > var t = a.join(); // 'a,b,c' > > But what happens if you call an array method on one of the *elements* of the > array? > > var x = a[0].join(); > > That's an error, because a[0] is a *string*, not an array. > > In the same way, $(whatever) returns a jQuery object, with jQuery methods > such as .val(), .css(), etc. The jQuery object is also an array-like object, > so you can retrieve the array elements with [0], [1], etc. But those array > elements are *DOM nodes*, not jQuery objects themselves. > > So, $(whatever)[0] gives you a DOM node, with properties like defaultValue, > but this DOM node does not have the jQuery methods, because it's not a > jQuery object. > > -Mike > > > for this form > > <form name="f1" method="get" action="/search" id="searchform" > > > <input type="text" name="q" value="Search...." size="70" /> > > <input type="submit" value="Search" /> > > </form> > > > why > > $("#searchform input")[0] > > is different than > > $("#searchform input:first") > > > I can get values for $("#searchform input")[0].defaultValue > > or .value but not with .fadeIn() or val() while the reverse > > for the $ ("#searchform input:first")
Beautifully said, Mike. That response should be on the docs wiki (maybe the FAQ page).