#13987 closed bug (notabug)
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.
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)
Note: See
TracTickets for help on using
tickets.
Your second append is appending the original element. See the docs:
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.