mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Fix #13810: .replaceWith(nextSibling)
(cherry picked from commit d8f7e83712
)
This commit is contained in:
parent
29b0e5202a
commit
d605322c10
@ -207,6 +207,10 @@ jQuery.fn.extend({
|
|||||||
parent = args[ i++ ];
|
parent = args[ i++ ];
|
||||||
|
|
||||||
if ( parent ) {
|
if ( parent ) {
|
||||||
|
// Don't use the snapshot next if it has moved (#13810)
|
||||||
|
if ( next && next.parentNode !== parent ) {
|
||||||
|
next = this.nextSibling;
|
||||||
|
}
|
||||||
jQuery( this ).remove();
|
jQuery( this ).remove();
|
||||||
parent.insertBefore( elem, next );
|
parent.insertBefore( elem, next );
|
||||||
}
|
}
|
||||||
|
@ -920,7 +920,7 @@ test( "insertAfter(String|Element|Array<Element>|jQuery)", function() {
|
|||||||
function testReplaceWith( val ) {
|
function testReplaceWith( val ) {
|
||||||
|
|
||||||
var tmp, y, child, child2, set, non_existent, $div,
|
var tmp, y, child, child2, set, non_existent, $div,
|
||||||
expected = 26;
|
expected = 29;
|
||||||
|
|
||||||
expect( expected );
|
expect( expected );
|
||||||
|
|
||||||
@ -996,6 +996,18 @@ function testReplaceWith( val ) {
|
|||||||
equal( set[0].childNodes.length, 0, "No effect on a disconnected node." );
|
equal( set[0].childNodes.length, 0, "No effect on a disconnected node." );
|
||||||
|
|
||||||
|
|
||||||
|
child = jQuery("#qunit-fixture").children().first();
|
||||||
|
$div = jQuery("<div class='pathological'/>").insertBefore( child );
|
||||||
|
$div.replaceWith( $div );
|
||||||
|
deepEqual( jQuery( ".pathological", "#qunit-fixture" ).get(), $div.get(),
|
||||||
|
"Self-replacement" );
|
||||||
|
$div.replaceWith( child );
|
||||||
|
deepEqual( jQuery("#qunit-fixture").children().first().get(), child.get(),
|
||||||
|
"Replacement with following sibling (#13810)" );
|
||||||
|
deepEqual( jQuery( ".pathological", "#qunit-fixture" ).get(), [],
|
||||||
|
"Replacement with following sibling (context removed)" );
|
||||||
|
|
||||||
|
|
||||||
non_existent = jQuery("#does-not-exist").replaceWith( val("<b>should not throw an error</b>") );
|
non_existent = jQuery("#does-not-exist").replaceWith( val("<b>should not throw an error</b>") );
|
||||||
equal( non_existent.length, 0, "Length of non existent element." );
|
equal( non_existent.length, 0, "Length of non existent element." );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user