kiran, 2011-12-04 06:02:
Confirmed.
I assume the problem is caused by the missing end tag for the list,
since list is then not closed yet.
Nothing to do with the missing closing tag, the browser deals with
that. Adding a closing tag doesn't fix the issue. Moving the script
element out of the UL does.
clone() will collect existing elements.
The expression jQuery('ul') does that, clone calls clone the clone
method of a jQuery object, which then calls .map which calls
jQuery.clone() which finally gets around to calling clonNode(true) -
and then does lost of weirdness, probably trying to fix "edge cases".
appendTo() will then append
thoes elements. I did not have a look to the code of jquery, but i
assume clone() will also see those elements which get created by appendTo().
There is certainly some weirdness going on. If you look at the code,
jQuery always creates a deep clone, then tries to fix attached events
(since those added with attachEvent are cloned but those added with
addEventListener aren't) and tries to fix obscure differences with
attributes on some elements.
In amongst all that, it gets lost. A jQuery object calls this
function:
clone: function( dataAndEvents, deepDataAndEvents ) {
dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
deepDataAndEvents = deepDataAndEvents == null ?
dataAndEvents : deepDataAndEvents;
return this.map( function () {
return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
});
},
which calls map and passes it jQuery.clone as the "callback"
map: function( callback ) {
return this.pushStack( jQuery.map(this, function( elem, i ) {
return callback.call( elem, i, elem );
}));
},
and jQuery.clone is:
jQuery.extend({
clone: function( elem, dataAndEvents, deepDataAndEvents ) {
var clone = elem.cloneNode(true),
srcElements,
destElements,
i;
if ( (!jQuery.support.noCloneEvent || !
jQuery.support.noCloneChecked) &&
(elem.nodeType === 1 || elem.nodeType === 11) &&
!jQuery.isXMLDoc(elem) ) {
// IE copies events bound via attachEvent when using cloneNode.
// Calling detachEvent on the clone will also remove the events
// from the original. In order to get around this, we use some
// proprietary methods to clear the events. Thanks to MooTools
// guys for this hotness.
cloneFixAttributes( elem, clone );
// Using Sizzle here is crazy slow, so we use
getElementsByTagName
// instead
srcElements = getAll( elem );
destElements = getAll( clone );
// Weird iteration because IE will replace the length property
// with an element if you are cloning the body and one of the
// elements on the page has a name or id of "length"
for ( i = 0; srcElements
; ++i ) {
// Ensure that the destination node is not null; Fixes #9587
if ( destElements ) {
cloneFixAttributes( srcElements, destElements );
}
}
}
// Copy the events from the original to the clone
if ( dataAndEvents ) {
cloneCopyEvent( elem, clone );
if ( deepDataAndEvents ) {
srcElements = getAll( elem );
destElements = getAll( clone );
for ( i = 0; srcElements; ++i ) {
cloneCopyEvent( srcElements, destElements );
}
}
}
srcElements = destElements = null;
// Return the cloned set
return clone;
},
In true jQuery style, it disappears up its own arse in convoluted
calls to all sorts of functions to "fix" things along the way. Someone
might care to trawl through all that to find the issue but I'm not
bothered.
No point guessing, it has nothing to do with the missing closing tag.
It is certainly something to do with the script element being within
the element being cloned, but why is for someone else to discover.
Care to log it as a bug?