Bug Tracker

Ticket #11226 (closed bug: fixed)

Opened 3 years ago

Last modified 22 months ago

.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:1 Changed 3 years ago by yurk

jquery 1.7.1 also affected

comment:2 Changed 3 years 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.

 http://jsfiddle.net/T2h4h/

comment:3 Changed 3 years 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 22 months ago by saiwong

This has been fixed in #12664.

Recommend ticket be closed.

comment:5 Changed 22 months ago by mikesherov

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

comment:6 Changed 22 months ago by mikesherov

  • Status changed from open to closed
  • Resolution set to fixed
  • Milestone changed from None to 1.9

fixed in #12664.

Note: See TracTickets for help on using tickets.