记录:append、appendChild、prepend对比及一个怪现象

拿项目做例子,要在ztree父节点添加图标


   
        
        数据。。。。。。。。
   

 

 第一个append

if (nodes.length > 0 && nodes != null) {
                            var arrow = document.createElement("i");
                            arrow.className = "fa fa-chevron-down";
                            arrow.id = "arrow";
                            $("#" + curMenu.tId + "_a.level0 span")[1].append(arrow);
                        }

记录:append、appendChild、prepend对比及一个怪现象_第1张图片                                

附加到文字后面去了

 第二个appendChild效果一样,也是加到后面

第三个prepend

if (nodes.length > 0 && nodes != null) {
                            var arrow = document.createElement("i");
                            arrow.className = "fa fa-chevron-down";
                            arrow.id = "arrow";
                            $("#" + curMenu.tId + "_a.level0 span")[1].prepend(arrow);
                        }

这次加到了文字前面 

 

 

怪现象:

记录:append、appendChild、prepend对比及一个怪现象_第2张图片

ztree的font-family生效的时候,自己附加的fontawesome图标就无法显示了

如果注释掉

记录:append、appendChild、prepend对比及一个怪现象_第3张图片          

就可以正常显示。

你可能感兴趣的:(html5,js)