javascript - Can we Directly remove Nodes from a NodeList? -


document.getelementsbytagname returned me nodelist object.

i remove items (let's remove first item nodelist)

is there way it? (i'm aware manually copy nodes array not wish if nodelist has functions remove elements in it)

i aware removing items nodelist has no effect on display (and should not cause browser-display-refresh or stuff that, not wish nodelist object hold referennce node)

is there way it? (or forced copy items in nodelist array?)

as can see in specification, there no method remove element list.

it not make sense anyway. nodelist live, meaning dom searched again whenever access property, e.g. length. mdc:

(...) returned list lis live, meaning updates dom tree automatically. (...)

so have to copy nodes array.

you can quite though using array methods. e.g. copy , directly remove first element:

var nodes = [].slice.call(elements, 1);  

the nodelist array-like object. hence can apply array functions it, using call [docs]. [].slice shorthand reference slice [docs] method.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -