javascript trying to remove all things with certain tags

后端 未结 2 1019
无人共我
无人共我 2021-01-23 05:19

I\'m trying to use javascript to remove everyhting with button or input tags from a page... So far my code removes some of them and I dont know why. It only removes one checkbox

2条回答
  •  臣服心动
    2021-01-23 05:27

    var checkboxes = document.getElementsByTagName("input");
    for (var j = 0; j < buttons.length ; j++) // You use the wrong variable here
    {
        checkboxes[j].parentNode.removeChild(checkboxes[j]);
    }
    

    Should be;

    for (var j = 0; j < checkboxes.length ; j++) 
    

    Regarding to the undeleted button, maybe it's because it's an input type="button" and not a

提交回复
热议问题