Bug Tracker

Modify

Ticket #7354 (closed bug: wontfix)

Opened 3 years ago

Last modified 2 years ago

order of cloned modified elements mismatches

Reported by: thorstengiese@… Owned by:
Priority: undecided Milestone: 1.5
Component: unfiled Version: 1.4.3
Keywords: Cc:
Blocking: Blocked by:

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

comment:1 Changed 3 years ago by anonymous

comment:2 Changed 3 years ago by thorstengiese@…

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 3 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 3 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 3 years ago by snover

  • Keywords needsdocs added
  • Status changed from new to closed
  • Resolution set to wontfix

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 2 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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.