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
69e6e535
Commit
69e6e535
authored
Sep 25, 2009
by
John Resig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding in .unwrap() support, thanks to Ben Alman! Fixes #5191.
parent
70b9aed4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
0 deletions
+39
-0
manipulation.js
src/manipulation.js
+8
-0
manipulation.js
test/unit/manipulation.js
+31
-0
No files found.
src/manipulation.js
View file @
69e6e535
...
@@ -90,6 +90,14 @@ jQuery.fn.extend({
...
@@ -90,6 +90,14 @@ jQuery.fn.extend({
});
});
},
},
unwrap
:
function
()
{
return
this
.
parent
().
each
(
function
(){
if
(
!
jQuery
.
nodeName
(
this
,
"body"
)
)
{
jQuery
(
this
).
replaceWith
(
this
.
childNodes
);
}
}).
end
();
},
append
:
function
()
{
append
:
function
()
{
return
this
.
domManip
(
arguments
,
true
,
function
(
elem
){
return
this
.
domManip
(
arguments
,
true
,
function
(
elem
){
if
(
this
.
nodeType
===
1
)
{
if
(
this
.
nodeType
===
1
)
{
...
...
test/unit/manipulation.js
View file @
69e6e535
...
@@ -116,6 +116,37 @@ test("wrapInner(String|Element)", function() {
...
@@ -116,6 +116,37 @@ test("wrapInner(String|Element)", function() {
// testWrapInner(functionReturningObj)
// testWrapInner(functionReturningObj)
// })
// })
var
testUnwrap
=
function
()
{
expect
(
9
);
jQuery
(
"body"
).
append
(
' <div id="unwrap" style="display: none;"> <div id="unwrap1"> <span class="unwrap">a</span> <span class="unwrap">b</span> </div> <div id="unwrap2"> <span class="unwrap">c</span> <span class="unwrap">d</span> </div> <div id="unwrap3"> <b><span class="unwrap unwrap3">e</span></b> <b><span class="unwrap unwrap3">f</span></b> </div> </div>'
);
var
abcd
=
jQuery
(
'#unwrap1 > span, #unwrap2 > span'
).
get
(),
abcdef
=
jQuery
(
'#unwrap span'
).
get
();
equals
(
jQuery
(
'#unwrap1 span, #unwrap2 span:first'
).
unwrap
().
length
,
3
,
'make #unwrap1 and #unwrap2 go away'
);
same
(
jQuery
(
'#unwrap > span'
).
get
(),
abcd
,
'all four spans should still exist'
);
same
(
jQuery
(
'#unwrap3 span'
).
unwrap
().
get
(),
jQuery
(
'#unwrap3 > span'
).
get
(),
'make all b in #unwrap3 go away'
);
same
(
jQuery
(
'#unwrap3 span'
).
unwrap
().
get
(),
jQuery
(
'#unwrap > span.unwrap3'
).
get
(),
'make #unwrap3 go away'
);
same
(
jQuery
(
'#unwrap'
).
children
().
get
(),
abcdef
,
'#unwrap only contains 6 child spans'
);
same
(
jQuery
(
'#unwrap > span'
).
unwrap
().
get
(),
jQuery
(
'body > span.unwrap'
).
get
(),
'make the 6 spans become children of body'
);
same
(
jQuery
(
'body > span.unwrap'
).
unwrap
().
get
(),
jQuery
(
'body > span.unwrap'
).
get
(),
'can
\'
t unwrap children of body'
);
same
(
jQuery
(
'body > span.unwrap'
).
unwrap
().
get
(),
abcdef
,
'can
\'
t unwrap children of body'
);
same
(
jQuery
(
'body > span.unwrap'
).
get
(),
abcdef
,
'body contains 6 .unwrap child spans'
);
jQuery
(
'body > span.unwrap'
).
remove
();
}
test
(
"unwrap()"
,
function
()
{
testUnwrap
();
});
var
testAppend
=
function
(
valueObj
)
{
var
testAppend
=
function
(
valueObj
)
{
expect
(
21
);
expect
(
21
);
var
defaultText
=
'Try them out:'
var
defaultText
=
'Try them out:'
...
...
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