Ticket #1955 (closed enhancement: invalid)
When no element matches the selector, the plugin function should not be exist
| Reported by: | bluenose | Owned by: | |
|---|---|---|---|
| Priority: | minor | Milestone: | 1.2.2 |
| Component: | core | Version: | 1.2.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
If we define a plugin, for example $.fn.example = ...
when $("#notexist").get().length == 0 the function example should not be executed. jQuery-1.1.3.js is ok for doing this. but jQuery-1.2.1 not.
Change History
comment:2 Changed 5 years ago by davidserduke
- Priority changed from major to minor
- Status changed from new to closed
- Resolution set to invalid
- Type changed from bug to enhancement
The author seems to be suggesting that when the jquery object has no objects it should stop calling functions such that
$([]).example();
Wouldn't execute the example() code. The author also seems to suggest that 1.1.3 didn't which seems unlikely but was before my time.
I don't see any compelling reason to attempt make this change. In fact, I can imagine situations where a plugin could still want to be called even when no elements were found (like a plugin that displays how many of a certain selector are found) so I'm going to close this bug on that basis. If there is an actual test case that can display an actual problem please reopen the bug with that test case.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Can you give an actual example of the problem you are experiencing? Or is this a design comment?