Uncaught HierarchyRequestError:追加节点失败
Uncaught HierarchyRequestError: Failed to append the node
我在向特定节点追加内容时遇到问题。这是我的Jsfidde http://jsfiddle.net/usezpkj2/7/
我有一个主列表
Project1
Project2
在Project1和project2中,隐藏的<ul class=hiddendivcontent
中有一些列表项,当点击glyhicon-chevron-down
时,列表将显示出来。下面是它的代码:
$(".glyphicon ").click( function ( e ){
e.preventDefault() // prevent default action - hash doesn't appear in url
var target = $(e.target);
if(target.hasClass("glyphicon-chevron-right")){
$(e.target).toggleClass('glyphicon-chevron-right glyphicon-chevron-down');
$(this).closest("li").append($('.hiddendivcontent'));
$(this).parent().children(".hiddendivcontent").toggle();
}
else if(target.hasClass("glyphicon-chevron-down")){
$(e.target).toggleClass('glyphicon-chevron-right glyphicon-chevron-down');
$(this).parent().children(".hiddendivcontent").toggle();
}
} );
当我点击列表项Menu1时,它应该再次追加<ul class="hiddendivcontent">..</ul>
作为Menu1内的子。最后我的输出应该是
Project1
Menu1
Menu1
Menu2
Menu2
Project2
问题是,当我点击菜单,我得到一个异常:
Uncaught HierarchyRequestError: Failed to execute 'appendChild' on 'Node': The new child element contains the parent.
问题在于追加符()。但是我不知道如何解决它。我是Jquery和Javascript的新手。谁能给我提些建议呢?
问题正是错误所描述的。你想添加:
<ul class="hiddendivcontent">
<li class="listvalue">Menu1</li>
<li class="listvalue">Menu2</li>
</ul>
自身内部。如果你想添加另一个看起来相同的html块,你可以这样做:
$(this).closest("li").append($('<ul class="NewList"> <li class="listvalue">Menu3</li></ul>'));
小提琴:http://jsfiddle.net/25q40a87/
相关文章:
- Angular Cross Origin Request CORS失败,但节点http.get()成功返回
- 使用Q节点模块时,Bluemix node.js应用程序部署失败
- 使用节点确定成功/失败.js函数 async.retry
- 节点VM-require()在第一级正常,在第二级失败
- 为什么这个茉莉花节点测试没有失败
- 1.js:23未捕获类型错误:执行'失败;appendChild'在'节点':参数1不是
- 节点中的 CORS 问题.js失败
- 更改节点内容 + JavaScript 失败
- 节点.js脚本由于代理问题而失败
- 节点断言错误未打印,断言以静默方式失败
- 节点 js 抓取失败
- 节点中的 RequireJS 因使用插件的依赖项(例如使用.js)而失败
- 谷歌数据存储查询中的多项选择抛出 API 错误:前提条件节点中失败错误
- 节点脚本需要向调用它的 Angular 服务返回成功/失败
- 对象节点到元素节点的转换失败
- 对节点应用程序进行群集时Socket.io websocket授权失败
- javascript xml节点相等比较在XSLT内的函数中失败
- 从强制布局中删除两个节点失败,而一个成功
- Uncaught HierarchyRequestError:追加节点失败
- DOMParser解析某些节点失败