Ticket #7176 (closed bug: invalid)
API Docs: Error in `after`
| Reported by: | T.J. Crowder | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.4.3 |
| Component: | web | Version: | 1.4.2 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
From http://api.jquery.com/after/:
As of jQuery 1.4, .before() and .after() will also work on disconnected DOM nodes. For example, given the following code:
$('<div/>').after('<p></p>');
The result is a jQuery set containing a div and a paragraph, in that order.
That's not correct. The jQuery set will still only contain the div; it's just that the paragraph will be added to the DOM after it (but not included in the jQuery object). Test: http://jsbin.com/onoqe4
Change History
comment:1 Changed 3 years ago by addyosmani
- Priority changed from undecided to low
- Resolution set to invalid
- Status changed from new to closed
- Component changed from unfiled to web
comment:2 Changed 3 years ago by T.J. Crowder
@addyosmani: I didn't see anywhere else to post an API docs bug, and this isn't the only API docs bug here. If there's somewhere else the docs bug should go, by all means point me to it.
Otherwise, this should not be closed. It is a bug. It misleads people relying on the documentation to provide valid information. Until or unless you replace it with a different means of tracking, and ultimately correcting, the bug, closing it is (to put it mildly) contrary to best practice.
comment:3 Changed 3 years ago by dmethvin
The docs are clarifying that .after() works slightly different for disconnected nodes. For example, if you enter this in the url, either here or at jsbin, you'll get the correct answer of 2:
javascript:alert($('<div/>').after('<p></p>').length)
The jsbin test case is *not* the same, it is not on disconnected nodes:
$('#foo').after('<p>bar</p>')
That is selecting a DOM element in the document and then inserting the paragraph after it.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

This isn't par se a jQuery core issue (more a docs one), however we will consider adjusting the language related to this particular API reference on our next review. I've added this to a queue of other API docs we're reviewing and will be closing this ticket so that it can be addressed there instead.