Child.parentNode.removeChild(child) Keeps Giving A TypeError: Cannot Read Property 'removeChild' Of Undefined
I'm new to JS and for an assignment I have to remove a div from a facebook post. I'm using to find the div, since FB doesn't use ID tags. I can get a value if i run the var but i
Solution 1:
getElementsByClassName returns list of elements.
Let us say you have a class with name "class1" attached to multiple elements inside the document, it will return all the elements with class name "class1". You can iterate though result of getElementsByClassName like normal array. For example:
if you want to remove first element that matches with this class name. then
el[0].parentNode.removeChild(el[0]).
But i would suggest having better logic to remove this element.
Post a Comment for "Child.parentNode.removeChild(child) Keeps Giving A TypeError: Cannot Read Property 'removeChild' Of Undefined"