Bug Tracker

Opened 12 years ago

Closed 12 years ago

#8513 closed bug (invalid)

Infinite loop when calling .each() on a null element

Reported by: [email protected] Owned by: [email protected]
Priority: undecided Milestone: 1.next
Component: core Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:


I noticed then when you call a jQuery('.unexistent-selector').each(function(){ ... do smthing ...}); generates an infinite loop. I marked this as a bug, as I think this should not happen since the element does not exists in the DOM tree. I think it would be better to raise an "undefined" exception - so notice the user that the element(s) he wants to iterate through could't be found.

Change History (2)

comment:1 Changed 12 years ago by Rick Waldron

Component: unfiledcore
Owner: set to [email protected]
Status: newpending

I cannot reproduce the error.


If you believe this is an incorrect assessment, please provide a reduced jsFiddle test case!

Additionally, test against the jQuery 0 GIT version to ensure the issue still exists.

comment:2 Changed 12 years ago by addyosmani

Resolution: invalid
Status: pendingclosed

Using rwaldron's test case above, I haven't been able to replicate this issue either. There doesn't seem to be any evidence of an infinite loop occurring. In addition, although there are a number of cases where we potentially could output an undefined exception internally, if you absolutely need this you could easily test for element existence prior to using $.each manually.

Note: See TracTickets for help on using tickets.