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
939e7551
Commit
939e7551
authored
Feb 11, 2015
by
Oleg Gaidarenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Manipulation: don't auto-insert tbody
Fixes gh-1835 Closes gh-2021 Ref e984d1c79cc476062818e03df04a366baa13d197
parent
b744a50d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
5 deletions
+81
-5
manipulation.js
src/manipulation.js
+6
-5
manipulation.js
test/unit/manipulation.js
+75
-0
No files found.
src/manipulation.js
View file @
939e7551
...
@@ -104,12 +104,13 @@ function getAll( context, tag ) {
...
@@ -104,12 +104,13 @@ function getAll( context, tag ) {
// Manipulating tables requires a tbody
// Manipulating tables requires a tbody
function
manipulationTarget
(
elem
,
content
)
{
function
manipulationTarget
(
elem
,
content
)
{
return
jQuery
.
nodeName
(
elem
,
"table"
)
&&
if
(
jQuery
.
nodeName
(
elem
,
"table"
)
&&
jQuery
.
nodeName
(
content
.
nodeType
!==
11
?
content
:
content
.
firstChild
,
"tr"
)
?
jQuery
.
nodeName
(
content
.
nodeType
!==
11
?
content
:
content
.
firstChild
,
"tr"
)
)
{
elem
.
getElementsByTagName
(
"tbody"
)[
0
]
||
return
elem
.
getElementsByTagName
(
"tbody"
)[
0
]
||
elem
;
elem
.
appendChild
(
elem
.
ownerDocument
.
createElement
(
"tbody"
)
)
:
}
elem
;
return
elem
;
}
}
// Replace/restore the type attribute of script elements for safe DOM manipulation
// Replace/restore the type attribute of script elements for safe DOM manipulation
...
...
test/unit/manipulation.js
View file @
939e7551
...
@@ -2485,6 +2485,81 @@ test( "Make sure jQuery.fn.remove can work on elements in documentFragment", 1,
...
@@ -2485,6 +2485,81 @@ test( "Make sure jQuery.fn.remove can work on elements in documentFragment", 1,
equal
(
fragment
.
childNodes
.
length
,
0
,
"div element was removed from documentFragment"
);
equal
(
fragment
.
childNodes
.
length
,
0
,
"div element was removed from documentFragment"
);
});
});
test
(
"Make sure tr element will be appended to tbody element of table when present"
,
function
()
{
expect
(
1
);
var
html
,
table
=
document
.
createElement
(
"table"
);
table
.
appendChild
(
document
.
createElement
(
"tbody"
)
);
document
.
getElementById
(
"qunit-fixture"
).
appendChild
(
table
);
jQuery
(
table
).
append
(
"<tr><td>test</td></tr>"
);
// Lowercase and replace spaces to remove possible browser inconsistencies
html
=
table
.
innerHTML
.
toLowerCase
().
replace
(
/
\s
/g
,
""
);
strictEqual
(
html
,
"<tbody><tr><td>test</td></tr></tbody>"
);
});
test
(
"Make sure tr elements will be appended to tbody element of table when present"
,
function
()
{
expect
(
1
);
var
html
,
table
=
document
.
createElement
(
"table"
);
table
.
appendChild
(
document
.
createElement
(
"tbody"
)
);
document
.
getElementById
(
"qunit-fixture"
).
appendChild
(
table
);
jQuery
(
table
).
append
(
"<tr><td>1</td></tr><tr><td>2</td></tr>"
);
// Lowercase and replace spaces to remove possible browser inconsistencies
html
=
table
.
innerHTML
.
toLowerCase
().
replace
(
/
\s
/g
,
""
);
strictEqual
(
html
,
"<tbody><tr><td>1</td></tr><tr><td>2</td></tr></tbody>"
);
});
test
(
"Make sure tfoot element will not be appended to tbody element of table when present"
,
function
()
{
expect
(
1
);
var
html
,
table
=
document
.
createElement
(
"table"
);
table
.
appendChild
(
document
.
createElement
(
"tbody"
)
);
document
.
getElementById
(
"qunit-fixture"
).
appendChild
(
table
);
jQuery
(
table
).
append
(
"<tfoot/>"
);
// Lowercase and replace spaces to remove possible browser inconsistencies
html
=
table
.
innerHTML
.
toLowerCase
().
replace
(
/
\s
/g
,
""
);
strictEqual
(
html
,
"<tbody></tbody><tfoot></tfoot>"
);
});
test
(
"Make sure document fragment will be appended to tbody element of table when present"
,
function
()
{
expect
(
1
);
var
html
,
fragment
=
document
.
createDocumentFragment
(),
table
=
document
.
createElement
(
"table"
),
tr
=
document
.
createElement
(
"tr"
),
td
=
document
.
createElement
(
"td"
);
table
.
appendChild
(
document
.
createElement
(
"tbody"
)
);
document
.
getElementById
(
"qunit-fixture"
).
appendChild
(
table
);
fragment
.
appendChild
(
tr
);
tr
.
appendChild
(
td
);
td
.
innerHTML
=
"test"
;
jQuery
(
table
).
append
(
fragment
);
// Lowercase and replace spaces to remove possible browser inconsistencies
html
=
table
.
innerHTML
.
toLowerCase
().
replace
(
/
\s
/g
,
""
);
strictEqual
(
html
,
"<tbody><tr><td>test</td></tr></tbody>"
);
});
test
(
"Make sure col element is appended correctly"
,
function
()
{
test
(
"Make sure col element is appended correctly"
,
function
()
{
expect
(
1
);
expect
(
1
);
...
...
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