Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jquery
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
jquery
Commits
8660ea1a
Commit
8660ea1a
authored
Feb 02, 2010
by
Noah Sloan
Committed by
jeresig
Feb 02, 2010
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only detach the incoming elements to replaceWith if they're DOM nodes. Fixes #5986.
parent
e76ba32c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
6 deletions
+13
-6
manipulation.js
src/manipulation.js
+5
-4
manipulation.js
test/unit/manipulation.js
+8
-2
No files found.
src/manipulation.js
View file @
8660ea1a
...
...
@@ -268,16 +268,17 @@ jQuery.fn.extend({
if
(
this
[
0
]
&&
this
[
0
].
parentNode
)
{
// Make sure that the elements are removed from the DOM before they are inserted
// this can help fix replacing a parent with child elements
if
(
!
jQuery
.
isFunction
(
value
)
)
{
value
=
jQuery
(
value
).
detach
();
}
else
{
if
(
jQuery
.
isFunction
(
value
)
)
{
return
this
.
each
(
function
(
i
)
{
var
self
=
jQuery
(
this
),
old
=
self
.
html
();
self
.
replaceWith
(
value
.
call
(
this
,
i
,
old
)
);
});
}
if
(
typeof
value
!==
"string"
)
{
value
=
jQuery
(
value
).
detach
();
}
return
this
.
each
(
function
()
{
var
next
=
this
.
nextSibling
,
parent
=
this
.
parentNode
;
...
...
test/unit/manipulation.js
View file @
8660ea1a
...
...
@@ -650,7 +650,7 @@ test("insertAfter(String|Element|Array<Element>|jQuery)", function() {
});
var
testReplaceWith
=
function
(
val
)
{
expect
(
1
5
);
expect
(
1
7
);
jQuery
(
'#yahoo'
).
replaceWith
(
val
(
'<b id="replace">buga</b>'
));
ok
(
jQuery
(
"#replace"
)[
0
],
'Replace element with string'
);
ok
(
!
jQuery
(
"#yahoo"
)[
0
],
'Verify that original element is gone, after string'
);
...
...
@@ -660,6 +660,12 @@ var testReplaceWith = function(val) {
ok
(
jQuery
(
"#first"
)[
0
],
'Replace element with element'
);
ok
(
!
jQuery
(
"#yahoo"
)[
0
],
'Verify that original element is gone, after element'
);
reset
();
jQuery
(
"#main"
).
append
(
'<div id="bar"><div id="baz">Foo</div></div>'
);
jQuery
(
'#baz'
).
replaceWith
(
"Baz"
);
equals
(
jQuery
(
"#bar"
).
text
(),
"Baz"
,
'Replace element with text'
);
ok
(
!
jQuery
(
"#baz"
)[
0
],
'Verify that original element is gone, after element'
);
reset
();
jQuery
(
'#yahoo'
).
replaceWith
(
val
(
[
document
.
getElementById
(
'first'
),
document
.
getElementById
(
'mark'
)]
));
ok
(
jQuery
(
"#first"
)[
0
],
'Replace element with array of elements'
);
...
...
@@ -721,7 +727,7 @@ test("replaceWith(String|Element|Array<Element>|jQuery)", function() {
test
(
"replaceWith(Function)"
,
function
()
{
testReplaceWith
(
functionReturningObj
);
expect
(
1
6
);
expect
(
1
8
);
var
y
=
jQuery
(
"#yahoo"
)[
0
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment