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 out of many, and 2 buttons (there are 3 buttons)
var buttons = document.getElementsByTagName("button");
for (var j = 0; j < buttons.length ; j++)
{
buttons[j].parentNode.removeChild(buttons[j]);
}
var checkboxes = document.getElementsByTagName("input");
for (var j = 0; j < buttons.length ; j++)
{
checkboxes[j].parentNode.removeChild(checkboxes[j]);
}
Should be;
Regarding to the undeleted button, maybe it’s because it’s an
input type="button"and not a<button>?Note that
document.getElementsByTagName("input");will get and delete later all the inputs, not just the checkboxes!May I suggest you using a javascript library like jQuery? you could have done this will one line of code with no problems: