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
7a67f889
Commit
7a67f889
authored
Jul 21, 2009
by
Yehuda Katz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds detach()
parent
29ff710c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
41 deletions
+66
-41
manipulation.js
src/manipulation.js
+10
-7
manipulation.js
test/unit/manipulation.js
+56
-34
No files found.
src/manipulation.js
View file @
7a67f889
...
@@ -249,18 +249,21 @@ jQuery.each({
...
@@ -249,18 +249,21 @@ jQuery.each({
});
});
jQuery
.
each
({
jQuery
.
each
({
remove
:
function
(
selector
)
{
// keepData is for internal use only--do not document
remove
:
function
(
selector
,
keepData
)
{
if
(
!
selector
||
jQuery
.
multiFilter
(
selector
,
[
this
]
).
length
)
{
if
(
!
selector
||
jQuery
.
multiFilter
(
selector
,
[
this
]
).
length
)
{
if
(
this
.
nodeType
===
1
)
{
if
(
!
keepData
&&
this
.
nodeType
===
1
)
{
cleanData
(
jQuery
(
"*"
,
this
).
add
(
this
)
);
cleanData
(
jQuery
(
"*"
,
this
).
add
(
this
)
);
}
}
if
(
this
.
parentNode
)
{
this
.
parentNode
&&
this
.
parentNode
.
removeChild
(
this
);
this
.
parentNode
.
removeChild
(
this
);
}
}
}
},
},
detach
:
function
(
selector
)
{
jQuery
(
this
).
remove
(
selector
,
true
)
},
empty
:
function
()
{
empty
:
function
()
{
// Remove element nodes and prevent memory leaks
// Remove element nodes and prevent memory leaks
if
(
this
.
nodeType
===
1
)
{
if
(
this
.
nodeType
===
1
)
{
...
...
test/unit/manipulation.js
View file @
7a67f889
...
@@ -677,24 +677,46 @@ test("text(Function)", function() {
...
@@ -677,24 +677,46 @@ test("text(Function)", function() {
testText
(
functionReturningObj
);
testText
(
functionReturningObj
);
})
})
test
(
"remove()"
,
function
()
{
var
testRemove
=
function
(
method
)
{
expect
(
7
);
expect
(
9
);
jQuery
(
"#ap"
).
children
().
remove
();
var
first
=
jQuery
(
"#ap"
).
children
(
":first"
);
first
.
data
(
"foo"
,
"bar"
);
jQuery
(
"#ap"
).
children
()[
method
]();
ok
(
jQuery
(
"#ap"
).
text
().
length
>
10
,
"Check text is not removed"
);
ok
(
jQuery
(
"#ap"
).
text
().
length
>
10
,
"Check text is not removed"
);
equals
(
jQuery
(
"#ap"
).
children
().
length
,
0
,
"Check remove"
);
equals
(
jQuery
(
"#ap"
).
children
().
length
,
0
,
"Check remove"
);
equals
(
first
.
data
(
"foo"
),
method
==
"remove"
?
null
:
"bar"
);
reset
();
reset
();
jQuery
(
"#ap"
).
children
()
.
remove
(
"a"
);
jQuery
(
"#ap"
).
children
()
[
method
]
(
"a"
);
ok
(
jQuery
(
"#ap"
).
text
().
length
>
10
,
"Check text is not removed"
);
ok
(
jQuery
(
"#ap"
).
text
().
length
>
10
,
"Check text is not removed"
);
equals
(
jQuery
(
"#ap"
).
children
().
length
,
1
,
"Check filtered remove"
);
equals
(
jQuery
(
"#ap"
).
children
().
length
,
1
,
"Check filtered remove"
);
jQuery
(
"#ap"
).
children
()
.
remove
(
"a, code"
);
jQuery
(
"#ap"
).
children
()
[
method
]
(
"a, code"
);
equals
(
jQuery
(
"#ap"
).
children
().
length
,
0
,
"Check multi-filtered remove"
);
equals
(
jQuery
(
"#ap"
).
children
().
length
,
0
,
"Check multi-filtered remove"
);
// using contents will get comments regular, text, and comment nodes
// using contents will get comments regular, text, and comment nodes
equals
(
jQuery
(
"#nonnodes"
).
contents
().
length
,
3
,
"Check node,textnode,comment remove works"
);
equals
(
jQuery
(
"#nonnodes"
).
contents
().
length
,
3
,
"Check node,textnode,comment remove works"
);
jQuery
(
"#nonnodes"
).
contents
()
.
remove
();
jQuery
(
"#nonnodes"
).
contents
()
[
method
]
();
equals
(
jQuery
(
"#nonnodes"
).
contents
().
length
,
0
,
"Check node,textnode,comment remove works"
);
equals
(
jQuery
(
"#nonnodes"
).
contents
().
length
,
0
,
"Check node,textnode,comment remove works"
);
reset
();
var
count
=
0
;
var
first
=
jQuery
(
"#ap"
).
children
(
":first"
);
first
.
click
(
function
()
{
count
++
})[
method
]().
appendTo
(
"body"
).
click
();
equals
(
method
==
"remove"
?
0
:
1
,
count
);
};
test
(
"remove()"
,
function
()
{
testRemove
(
"remove"
);
});
test
(
"detach()"
,
function
()
{
testRemove
(
"detach"
);
});
});
test
(
"empty()"
,
function
()
{
test
(
"empty()"
,
function
()
{
...
...
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