removeChild based on tagnode.map is not a function error

I have a function that selects all elements with tag a and removes the parent´s parent node if a class is applied to them however I am getting an error in firebug that states it is not a function

function groupSelectedElements() {
    document.getElementById(form_values[0]).getElementsByTagName('a').map(function (value) {
		if (value.className === 'checkbox checkbox_c') {
		document.getElementById(form_values[0]).removeChild(value.parentNode.parentNode.id);
		}
	});
}

firebug says

document.getElementById(form_values[0]).getElementsByTagName("a").map is not a function
groupSelectedElements()form_create.php (line 440)
onclick()4 (line 3)
event = click clientX=748, clientY=182

What you have there with getElementsByTagName is node list, not an array.

One way to deal with that is to explicitly call the array map method and pass the node list to it.


var els = document.getElementById(form_values[0]).getElementsByTagName('a');
Array.prototype.map(els, function () {
    ...
});

If you find that some web browsers don’t support the array map method that you are using there (internet explorer being one of them), then the array.map() page has compatibility code for that.

Thank you so much, that worked, this is what the function ended up like:

function groupSelectedElements() {
    Array.prototype.slice.call(document.getElementById(form_values[0]).getElementsByTagName('a')).map(function (value) {
        if (value.className === 'checkbox checkbox_c') {
        document.getElementById(form_values[0]).removeChild(document.getElementById(value.parentNode.parentNode.id));
        }
	});
}