JavaScript remove all elements with name

javascript

Solution

I don't have enough rep to comment on Álvaro G. Vicario. The reason that it works is that the element is removed from ele when it is removed from the DOM. Weird.

The following code should work equally well:

var ele= document.getElementsByName("javascriptaudio");
len = ele.length;
parentNode = ele[0].parentNode;
for(var i=0; i<len; i++)
{
  parentNode.removeChild(ele[0]);
}

Problem

I am trying to use JavaScript to remove all the elements with a certian name, but it is only removing the first one. My code is: ``` var ele= document.getElementsByName("javascriptaudio"); for(var i=0;i<ele.length;i++) { ele[i].parentNode.removeChild(ele[i]); } ``` Can anyone tell me what is wrong? Thanks

Original source