Opened 12 years ago
Closed 11 years ago
#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: | ||
Blocked by: | Blocking: |
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 (6)
comment:1 Changed 12 years ago by
comment:2 Changed 12 years ago by
Component: | unfiled → manipulation |
---|---|
Priority: | undecided → high |
Status: | new → open |
Version: | 1.6.4 → 1.7.1 |
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 12 years ago by
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:5 Changed 11 years ago by
Thanks for catching these, Sai. We'll close after discussing in the meeting today!
comment:6 Changed 11 years ago by
Milestone: | None → 1.9 |
---|---|
Resolution: | → fixed |
Status: | open → closed |
fixed in #12664.
jquery 1.7.1 also affected