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
23d600c6
Commit
23d600c6
authored
Jan 11, 2010
by
jeresig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure that wrapInner works on elements that have no contents. Fixes #3552.
parent
3e9ef6f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
manipulation.js
src/manipulation.js
+8
-1
manipulation.js
test/unit/manipulation.js
+6
-1
No files found.
src/manipulation.js
View file @
23d600c6
...
...
@@ -77,7 +77,14 @@ jQuery.fn.extend({
wrapInner
:
function
(
html
)
{
return
this
.
each
(
function
()
{
jQuery
(
this
).
contents
().
wrapAll
(
html
);
var
self
=
jQuery
(
this
),
contents
=
self
.
contents
();
if
(
contents
.
length
)
{
contents
.
wrapAll
(
html
);
}
else
{
self
.
append
(
html
);
}
});
},
...
...
test/unit/manipulation.js
View file @
23d600c6
...
...
@@ -145,7 +145,7 @@ test("wrapAll(String|Element)", function() {
// })
var
testWrapInner
=
function
(
val
)
{
expect
(
6
);
expect
(
8
);
var
num
=
jQuery
(
"#first"
).
children
().
length
;
var
result
=
jQuery
(
'#first'
).
wrapInner
(
'<div class="red"><div id="tmp"></div></div>'
);
equals
(
jQuery
(
"#first"
).
children
().
length
,
1
,
"Only one child"
);
...
...
@@ -158,6 +158,11 @@ var testWrapInner = function(val) {
equals
(
jQuery
(
"#first"
).
children
().
length
,
1
,
"Only one child"
);
ok
(
jQuery
(
"#first"
).
children
().
is
(
"#empty"
),
"Verify Right Element"
);
equals
(
jQuery
(
"#first"
).
children
().
children
().
length
,
num
,
"Verify Elements Intact"
);
var
div
=
jQuery
(
"<div/>"
);
div
.
wrapInner
(
"<span></span>"
);
equals
(
div
.
children
().
length
,
1
,
"The contents were wrapped."
);
equals
(
div
.
children
()[
0
].
nodeName
.
toLowerCase
(),
"span"
,
"A span was inserted."
);
}
test
(
"wrapInner(String|Element)"
,
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