Skip to main content

Bug Tracker

Side navigation

#7176 closed bug (invalid)

Opened October 13, 2010 02:04PM UTC

Closed October 13, 2010 04:26PM UTC

Last modified October 14, 2010 05:45AM UTC

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:
Blocked by: Blocking:
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

Attachments (0)
Change History (4)

Changed October 13, 2010 04:26PM UTC by addyosmani comment:1

component: unfiledweb
priority: undecidedlow
resolution: → invalid
status: newclosed

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.

Changed October 13, 2010 06:46PM UTC by T.J. Crowder comment:2

@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.

Changed October 14, 2010 02:15AM UTC by dmethvin comment:3

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.

Changed October 14, 2010 05:45AM UTC by T.J. Crowder comment:4

@dmethvin & addyosmani: Yikes, I cannot ''believe'' I missed it was talking about disconnected nodes. I mean, it's ''right there in the text I quoted'' in this bug report!

With disconnected nodes, it does exactly what it says. Sorry for the hassle.

-- T.J.