我正在尝试删除第一个li
in an ol
使用 DOMremoveChild()
。但由于某种原因它不起作用。
这是我的 JavaScript:
document.getElementById('queue').removeChild(
document.getElementById('queue').childNodes[0]
);
这是我的 HTML:
<ol id="queue">
<li>Surprised Kitty (Original)<span class="nodisplay">0Bmhjf0rKe8</span></li></ol>
我尝试提醒childNodes[0]
,并且它返回[Object Text]
,这看起来有点奇怪,当我只期待这个物体时。
希望我已经说清楚了。
试试这个单行:
document.getElementById('queue').removeChild(document.getElementById('queue').getElementsByTagName('li')[0]);
扩展解释:
var queue = document.getElementById('queue'); // Get the list whose id is queue.
var elements = queue.getElementsByTagName('li'); // Get HTMLCollection of elements with the li tag name.
queue.removeChild(elements[0]); // Remove the child from queue that is the first li element.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)