Personally, I always use this form:

var tempList = $(...);
if (tempList.length) {
  // perform actions on tempList or tempList[0]
}

I've always run into trouble assuming that actions on an empty set will be
ignored. (I agree that this should be fixed, but it's a decent workaround
for the time being.)


jgrucza wrote:
> 
> I just tried upgrading to 1.1.1, but immediately found a problem.  I have
> this little bit of code that puts the focus in the first form field with a
> class of "focus".  Not all pages will have an element with this class. 
> Here is the code that used to work fine:
> 
>         var focused = $(".focus").get(0);
>         if (focused) { focused.focus(); focused.select(); }
> 
> But after upgrading to 1.1.1, I got an error saying focus() wasn't a
> method.  So I added a little debugging alert, and apparently,
> $(".focus").get(0) is returning the document object!  If I call
> $(".focus").size() it returns 0, but yet when I call .get(0) it's
> returning something?  Anyone else seeing this?
> 
-- 
View this message in context: 
http://www.nabble.com/in-1.1.1%2C-get%280%29-returns-the-document-when-it-shouldn%27t-be-returning-anything%21-tf3058953.html#a8525503
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to