Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何删除不使用getElementById的特定元素?_Javascript - Fatal编程技术网

Javascript 如何删除不使用getElementById的特定元素?

Javascript 如何删除不使用getElementById的特定元素?,javascript,Javascript,在下面的代码中,我如何删除ul id=“videos\u list”>之间的所有元素li class=“…”,但具有“a id=“id\u defined\u here”的元素除外? 无法删除“ul id=”视频列表“>” //Above, other classes and stuff. <ul id="videos_list"> <li class="" style="background-color: rgb(246, 237, 245);"> … <

在下面的代码中,我如何删除
ul id=“videos\u list”>
之间的所有元素
li class=“
…”,但具有“a id=“id\u defined\u here”的元素除外? 无法删除“ul id=”视频列表“>”

//Above, other classes and stuff.
 <ul id="videos_list">
    <li class="" style="background-color: rgb(246, 237, 245);"> … </li>
    <li class="" style="background-color: rgb(246, 237, 245);">
        <a id="a_32447256" class="aVideo" ai="2474759"> … </a> 
        <p> … </p>
        <p class="list_lastUp" style="display: block;"> … </p>
        <div class="visuVideo" original-title="visualões"> … </div>
    </li>
    <li class="" style="background-color: rgb(246, 237, 245);"> … </li>
    <li class="" style="background-color: rgb(246, 237, 245);"> … </li>
</ul>
//Bellow, other classes and stuff.
唯一不能删除的“li class=”“…>”是那个有id=a_32447256的孩子的人。这就是我使用 myNode.firstChild.firstChild,但不起作用

我能做些什么来解决这个问题

谢谢大家!

var ul  = document.getElementById('videos_list'),
    li  = ul.getElementsByTagName('li'),
    not = document.getElementById('a_32447256').parentNode;

for (var i=li.length; i--;) {
    if ( li[i] != not ) ul.removeChild(li[i]);
}

Array.prototype.slice.call(document.queryselectoral('#videos_list>li')).forEach(函数(元素){
if(element.querySelector('a_32447256')。长度
var ul  = document.getElementById('videos_list'),
    li  = ul.getElementsByTagName('li'),
    not = document.getElementById('a_32447256').parentNode;

for (var i=li.length; i--;) {
    if ( li[i] != not ) ul.removeChild(li[i]);
}
Array.prototype.slice.call(document.querySelectorAll('#videos_list > li')).forEach(function(element){
    if(element.querySelector('a_32447256').length <1){
        document.querySelector('#videos_list').removeChild(element);
    }
})
var list = document.getElementById('videos_list'),
    target = document.getElementById('a_32447256');

while (list.firstChild) {
    list.removeChild(list.firstChild);
}
list.appendChild(target.parentNode);
var keep = document.getElementById('a_32447256').parentNode;
var root = document.getElementById('videos_list');

[].slice.call(root.children).forEach(function(node) {
   if ( node !== keep ) this.removeChild(node);
}, root);