如果我按照以下步骤进行操作,那么就可以顺利完成:
<div id="results">
<p>Hello<br>there</p>
</div>
$($("#results p").children('br').get(0).nextSibling).remove();
I get: hello
But if I do:
<th class="infobox">Head</th>
<td>Hello<br>there</td>
var newLineRemove = $(".infobox td").children('br').get(0).nextSibling();
$wikiDOM.find(newLineRemove).remove();
这个错误信息是“未捕获类型错误:无法读取未定义的 nextSibling 属性”。
<td>
不在.infobox
里面,所以你的选择器$(".infobox td")
没有返回任何内容,因此你对.children('br')
的调用也不会有任何结果? - Forty3$($(".infobox").next("td").children("br")[0].nextSibling).remove()
- nnnnnn)
,这不是什么高深的科学(我已经编辑了我的评论)。在那之后,你的小样就无法工作了,因为你把 TD 和 TH 放在了 TABLE 外面,所以浏览器不会将它们视为 TD 和 TH - 把它们放在一个带有 TR 的 TABLE 中,它就可以工作了:https://jsfiddle.net/pz3ce0o6/1018/。 - nnnnnn