Javascript 未知文本节点
为什么我在附加到父div的console.log元素上添加了一堆回车节点。有没有办法消除这个问题,因为当我尝试向它们添加一些css时,它们会破坏应用程序 这是我的设置。我正在使用下划线模板创建我的html。tmpl工作正常Javascript 未知文本节点,javascript,jquery,dom,Javascript,Jquery,Dom,为什么我在附加到父div的console.log元素上添加了一堆回车节点。有没有办法消除这个问题,因为当我尝试向它们添加一些css时,它们会破坏应用程序 这是我的设置。我正在使用下划线模板创建我的html。tmpl工作正常 var tmpl = $( template({items : list}) ); var items = $(_.filter(tmpl, function(item){ return ! $item.hasClass('pin');
var tmpl = $( template({items : list}) );
var items = $(_.filter(tmpl, function(item){
return ! $item.hasClass('pin');
}));
var domItems = items.appendTo($('.container'));
这是日志
domItems =
[<TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item, <TextNode textContent="\n \n ">, div.item]
域名=
[,div.item,div.item,div.item,div.item,div.item,div.item,div.item,,div.item,div.item,div.item,div.item,div.item,div.item,div.item,div.item]
<>我只想让它返回DIV.元素元素 一些浏览器将空空间视为文本节点。要过滤它们,只需排除所有等于
3
()的nodeType
s即可:
var items = $(_.filter(tmpl, function(item){
return ! $item.hasClass('pin') && this.nodeType !== 3;
}));