Skip to main content

Bug Tracker

Side navigation

#11226 closed bug (fixed)

Opened January 25, 2012 08:06PM UTC

Closed October 22, 2012 04:06PM UTC

.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/>'

Attachments (0)
Change History (6)

Changed January 25, 2012 08:13PM UTC by yurk comment:1

jquery 1.7.1 also affected

Changed January 25, 2012 08:18PM UTC by dmethvin comment:2

component: unfiledmanipulation
priority: undecidedhigh
status: newopen
version: 1.6.41.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.

http://jsfiddle.net/T2h4h/

Changed January 26, 2012 11:27AM UTC by yurk comment:3

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.

Changed October 22, 2012 03:32PM UTC by saiwong comment:4

This has been fixed in #12664.

Recommend ticket be closed.

Changed October 22, 2012 04:02PM UTC by mikesherov comment:5

Thanks for catching these, Sai. We'll close after discussing in the meeting today!

Changed October 22, 2012 04:06PM UTC by mikesherov comment:6

milestone: None1.9
resolution: → fixed
status: openclosed

fixed in #12664.