【发布时间】:2019-10-22 02:41:23
【问题描述】:
我尝试删除 jquery 代码并将其转换为纯 js
//old code in jquery
const item = $('[type=item]')
item.text() === '' && $(item).remove()
//new code without jquery
const item = document.querySelector('[type="item"]')
item.innerText === '' && item.parentNode.removeChild(item) // this is problem
但是我使用第二个代码块得到了不同的行为,我想我错误地使用了 removeChild。
【问题讨论】:
-
或许你可以试试
item.parentElement.removeChild? -
您能描述一下您在两种方法之间观察到的不同行为吗?
标签: javascript jquery ecmascript-6