Skip to main content

Bug Tracker

Side navigation

#13987 closed bug (notabug)

Opened June 04, 2013 01:23PM UTC

Closed June 04, 2013 01:44PM UTC

Last modified June 04, 2013 01:55PM UTC

Appending jquery objects to multiple elements fails under certain conditions

Reported by: ctrl1alt1del Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 2.0.2
Keywords: Cc:
Blocked by: Blocking:
Description

Appending a Jquery object, which has been stored as a variable, to multiple elements fails to append the object to all of the matched elements. The jsfiddle below demonstrates an example of the behavior. It shows that only one of the elements selected with a class selector receives the appended object. This occurs when the same Jquery object variable is appended to another element later in the code block.


http://jsfiddle.net/ZEBKK/


Browsers affected:

Firefox 21.0 with Jquery 2.0.2

Google Chrome 27.0.1453.94 m with Jquery 2.0.2

Internet Explorer 9 with 2.0.2 on my local machine and Jquery 1.9.1 inside jsfiddle(2.0.2 doesn't run at all)

Attachments (0)
Change History (2)

Changed June 04, 2013 01:44PM UTC by dmethvin comment:1

resolution: → notabug
status: newclosed

Your second append is appending the original element. See the docs:

If there is more than one target element, however, cloned copies of the inserted element will be created for each target after the first. -- http://api.jquery.com/append/

Docs correction, it should say _except the last_ instead of _after the first_ there, but the behavior is expected. I've created https://github.com/jquery/api.jquery.com/issues/318 to correct that.

If you are going to create a template-ish element and want to always copy rather than move, use .clone().append() instead.

Changed June 04, 2013 01:55PM UTC by ctrl1alt1del comment:2

Thanks for the clarification and docs correction.