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
1b610266
Commit
1b610266
authored
Apr 05, 2013
by
Dave Methvin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #13721. Filter before .remove() loop so positionals work. Close gh-1221.
parent
5031c9db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
16 deletions
+27
-16
manipulation.js
src/manipulation.js
+11
-13
manipulation.js
test/unit/manipulation.js
+16
-3
No files found.
src/manipulation.js
View file @
1b610266
...
@@ -72,23 +72,21 @@ jQuery.fn.extend({
...
@@ -72,23 +72,21 @@ jQuery.fn.extend({
// keepData is for internal use only--do not document
// keepData is for internal use only--do not document
remove
:
function
(
selector
,
keepData
)
{
remove
:
function
(
selector
,
keepData
)
{
var
elem
,
var
elem
,
i
=
0
,
elems
=
selector
?
jQuery
.
filter
(
selector
,
this
)
:
this
,
l
=
thi
s
.
length
;
i
=
elem
s
.
length
;
for
(
;
i
<
l
;
i
++
)
{
while
(
i
--
)
{
elem
=
thi
s
[
i
];
elem
=
elem
s
[
i
];
if
(
!
selector
||
jQuery
.
filter
(
selector
,
[
elem
]
).
length
>
0
)
{
if
(
!
keepData
&&
elem
.
nodeType
===
1
)
{
if
(
!
keepData
&&
elem
.
nodeType
===
1
)
{
jQuery
.
cleanData
(
getAll
(
elem
)
);
jQuery
.
cleanData
(
getAll
(
elem
)
);
}
}
if
(
elem
.
parentNode
)
{
if
(
elem
.
parentNode
)
{
if
(
keepData
&&
jQuery
.
contains
(
elem
.
ownerDocument
,
elem
)
)
{
if
(
keepData
&&
jQuery
.
contains
(
elem
.
ownerDocument
,
elem
)
)
{
setGlobalEval
(
getAll
(
elem
,
"script"
)
);
setGlobalEval
(
getAll
(
elem
,
"script"
)
);
}
elem
.
parentNode
.
removeChild
(
elem
);
}
}
elem
.
parentNode
.
removeChild
(
elem
);
}
}
}
}
...
...
test/unit/manipulation.js
View file @
1b610266
...
@@ -1713,7 +1713,8 @@ test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function()
...
@@ -1713,7 +1713,8 @@ test( "clone()/html() don't expose jQuery/Sizzle expandos (#12858)", function()
});
});
var
testRemove
=
function
(
method
)
{
var
testRemove
=
function
(
method
)
{
var
first
=
jQuery
(
"#ap"
).
children
().
first
();
var
markup
,
div
,
first
=
jQuery
(
"#ap"
).
children
().
first
();
first
.
data
(
"foo"
,
"bar"
);
first
.
data
(
"foo"
,
"bar"
);
...
@@ -1731,6 +1732,18 @@ var testRemove = function( method ) {
...
@@ -1731,6 +1732,18 @@ var testRemove = function( method ) {
jQuery
(
"#ap"
).
children
()[
method
](
"a, code"
);
jQuery
(
"#ap"
).
children
()[
method
](
"a, code"
);
equal
(
jQuery
(
"#ap"
).
children
().
length
,
0
,
"Check multi-filtered remove"
);
equal
(
jQuery
(
"#ap"
).
children
().
length
,
0
,
"Check multi-filtered remove"
);
// Positional and relative selectors
markup
=
"<div><span>1</span><span>2</span><span>3</span><span>4</span></div>"
;
div
=
jQuery
(
markup
);
div
.
children
().
remove
(
"span:nth-child(2n)"
);
equal
(
div
.
text
(),
"13"
,
"relative selector in "
+
method
);
div
=
jQuery
(
markup
);
div
.
children
().
remove
(
"span:first"
);
equal
(
div
.
text
(),
"234"
,
"positional selector in "
+
method
);
div
=
jQuery
(
markup
);
div
.
children
().
remove
(
"span:last"
);
equal
(
div
.
text
(),
"123"
,
"positional selector in "
+
method
);
// using contents will get comments regular, text, and comment nodes
// using contents will get comments regular, text, and comment nodes
// Handle the case where no comment is in the document
// Handle the case where no comment is in the document
ok
(
jQuery
(
"#nonnodes"
).
contents
().
length
>=
2
,
"Check node,textnode,comment remove works"
);
ok
(
jQuery
(
"#nonnodes"
).
contents
().
length
>=
2
,
"Check node,textnode,comment remove works"
);
...
@@ -1743,7 +1756,7 @@ var testRemove = function( method ) {
...
@@ -1743,7 +1756,7 @@ var testRemove = function( method ) {
}
}
};
};
test
(
"remove()"
,
8
,
function
()
{
test
(
"remove()"
,
11
,
function
()
{
testRemove
(
"remove"
);
testRemove
(
"remove"
);
});
});
...
@@ -1762,7 +1775,7 @@ test( "remove() event cleaning ", 1, function() {
...
@@ -1762,7 +1775,7 @@ test( "remove() event cleaning ", 1, function() {
cleanUp
.
remove
();
cleanUp
.
remove
();
});
});
test
(
"detach()"
,
8
,
function
()
{
test
(
"detach()"
,
11
,
function
()
{
testRemove
(
"detach"
);
testRemove
(
"detach"
);
});
});
...
...
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