Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#7354 closed bug (wontfix)

order of cloned modified elements mismatches

Reported by: [email protected] 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>

Change History (6)

comment:1 Changed 12 years ago by anonymous

comment:2 Changed 12 years ago by [email protected]

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

comment:3 Changed 12 years ago by snover

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.

comment:4 Changed 12 years ago by jitter

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.

comment:5 Changed 12 years ago by snover

Keywords: needsdocs added
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.

comment:6 Changed 12 years ago by addyosmani

Keywords: needsdocs removed

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

Note: See TracTickets for help on using tickets.