Ticket #11226 (closed bug: fixed)
.after and .before returns incorrect data for $('not_existing_element')
| Reported by: | yurk | Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | 1.9 |
| Component: | manipulation | Version: | 1.7.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
$('existing_element').after('<h2/>');
$('existing_element').before('<h2/>');
expected: return a jquery object for '<existing_element>'
actually: works as expected
$('not_existing_element').after('<h2/>');
$('not_existing_element').before('<h2/>');
expected: return an empty jquery object
actually: returns a jquery object for newly created '<h2/>'
Change History
comment:2 Changed 17 months ago by dmethvin
- Priority changed from undecided to high
- Status changed from new to open
- Version changed from 1.6.4 to 1.7.1
- Component changed from unfiled to manipulation
Wow, interesting case. And by interesting I mean pain in the ass.
At some point a while back we decided to support things like $("<p>hello</p>").after("<p>world</p>") to get you two paragraphs in the collection. Prior to that I don't recall what it did, probably broke.
I agree though that it seems wrong to have .after() or .before() add stuff to an empty collection. I wonder whose code we'll break by fixing this.
comment:3 Changed 17 months ago by yurk
Yes, adding stuff to a primary collection by .after() and .before() is not so useful for chain-style coding.
An another bug posted into http://bugs.jquery.com/ticket/11230 could be related to this.
comment:4 Changed 8 months ago by saiwong
This has been fixed in #12664.
Recommend ticket be closed.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

jquery 1.7.1 also affected