我想检查 nextElementSibling 元素是否存在以及它是否是一个字段。但是我没有找到正确的 JS 请求。
document.getElementById($id).nextElementSibling.type
不起作用。
最佳答案
您需要使用 nodeName 或 tagName。
var nextElement = document.getElementById('demo').nextElementSibling.nodeName;
console.log(nextElement);
<div id="demo">
<p>
hola
</p>
</div>
<p>
next element
</p>
关于javascript - 如何通过JS获取nextElementSibling类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54571755/