Skip to main content

Bug Tracker

Side navigation

#7354 closed bug (wontfix)

Opened October 29, 2010 10:14PM UTC

Closed October 31, 2010 01:06AM UTC

Last modified May 16, 2011 05:26AM UTC

order of cloned modified elements mismatches

Reported by: thorstengiese@gmail.com Owned by:
Priority: undecided Milestone: 1.5
Component: unfiled Version: 1.4.3
Keywords: Cc:
Blocked by: Blocking:
Description

With more than 8 elements in the "orig"-div, jQuery mixes up the order in the "copy"-div.

Here is the code:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div id="orig">
<div class="elem"><a>1</a></div>
<div class="elem"><a>2</a></div>
<div class="elem"><a>3</a></div>
<div class="elem"><a>4</a></div>
<div class="elem"><a>5</a></div>
<div class="elem"><a>6</a></div>
<div class="elem"><a>7</a></div>
<div class="elem"><a>8</a></div>
<div class="elem"><a>9</a></div>
</div>

<div id="copy"></div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script>
$(function() {
  $('#copy').append($('.elem').clone().children('a').prepend('foo - ').parent().clone());
});
</script>
</body>
</html>
Attachments (0)
Change History (6)

Changed October 29, 2010 10:15PM UTC by anonymous comment:1

Changed October 29, 2010 10:29PM UTC by thorstengiese@gmail.com comment:2

Additional Info: Works fine on Safari/iPad, seems to be Browser dependend. Firefox 3.6 under Windows 7 was used for detection.

Changed October 29, 2010 10:42PM UTC by snover comment:3

revised test case

I am 99% sure this is not a jQuery bug. Your code is cloning a collection of elements that is not attached to any DOM and so has no order. The revised test case contains the correct code for doing what you are trying to do, and the order is consistent.

Changed October 29, 2010 11:24PM UTC by jitter comment:4

I agree with snover.


The following is just further info.

The test provided by anonymous (thorstengiese ?) in Opera inserts them in reverse order 9,8,...,2,1. But just adapting the test to correct jsfiddle conventions fixes it for Opera as in snovers revised testcase both calls insert in correct order 1,2,...,8,9. But in FF 3.6 only the second (correct) usage works.

Changed October 31, 2010 01:06AM UTC by snover comment:5

keywords: → needsdocs
resolution: → wontfix
status: newclosed

When nodes are disconnected, we can’t guarantee sort order. I’ll make sure the docs get updated somewhere appropriate to reflect this.

Changed May 16, 2011 05:26AM UTC by addyosmani comment:6

keywords: needsdocs

docs have been updated for .clone() using a slightly modified version of snover's test case as a live inline example.