admin管理员组文章数量:1391929
I did find several questions concerning the NOT_FOUND_ERR: DOM Exception 8
error in bination with jQuery, but they did not happen in a scenario like mine and as such they did not provide a solution.
Basically, I have an object and I'm iterating over it and then adding rows to a <table>
with id="legend"
: /.
var items = [],
obj = {a: 1,
b: 2};
$.each(obj, function(i, v) {
items.push(
$("<tr>").append(
$("<td>").html(i),
$("<td>").html(v)
)
);
});
// .empty() is to erase contents when running this piece of code again
$("#legend").empty().append(
$(items)
);
When I run this piece of code, I get the error:
Uncaught Error: NOT_FOUND_ERR: DOM Exception 8
on Chrome.
I'm not sure what exactly is wrong with my code.
- What cannot be found?
- How can I solve this issue?
I did find several questions concerning the NOT_FOUND_ERR: DOM Exception 8
error in bination with jQuery, but they did not happen in a scenario like mine and as such they did not provide a solution.
Basically, I have an object and I'm iterating over it and then adding rows to a <table>
with id="legend"
: http://jsfiddle/nt9gZ/.
var items = [],
obj = {a: 1,
b: 2};
$.each(obj, function(i, v) {
items.push(
$("<tr>").append(
$("<td>").html(i),
$("<td>").html(v)
)
);
});
// .empty() is to erase contents when running this piece of code again
$("#legend").empty().append(
$(items)
);
When I run this piece of code, I get the error:
Uncaught Error: NOT_FOUND_ERR: DOM Exception 8
on Chrome.
I'm not sure what exactly is wrong with my code.
- What cannot be found?
- How can I solve this issue?
5 Answers
Reset to default 4You are trying to insert an array of arrays..
Add a .get(0)
when you are pushing the created object in the array, so that you insert the actual DOM fragments..
$.each(obj, function(i, v) {
items.push(
$("<tr>").append(
$("<td>").html(i),
$("<td>").html(v)
).get(0)
);
});
demo at http://jsfiddle/gaby/nt9gZ/7/
I've update your code a bit: http://jsfiddle/nt9gZ/8/
Basically there problem with the array - append
method does not take array of jQuery objects as an argument, only a sequence of elements. So I've used add
method to collect all rows together.
I am not familiar with your below code
$("<tr>").append(
$("<td>").html(i),
$("<td>").html(v)
)
But here is another way to achieve the same.
var items = [],
obj = {a: 1, b: 2};
$.each(obj, function(i, v) {
items.push("<tr>"+"<td>"+i+"</td><td>" + v +"</td></tr>");
});
$("#legend").append(items.join(""));
from your jsfiddle
Append do not expect array in the first argument. However, reading the doc, the second arg can be an array. I can't manage to pass an array and make it work (as the second argument) though.
Try this jsfiddle
you should loop over items in items
array and append 'em one by one
本文标签: javascriptNOTFOUNDERR when appending to table using jQueryStack Overflow
版权声明:本文标题:javascript - NOT_FOUND_ERR when appending to table using jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744700951a2620558.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论