child.parentNode.removeChild(child) keeps giving a TypeError: Cannot read property 'removeChild' of undefined

Dylan Nicholson

I'm new to JS and for an assignment I have to remove a div from a facebook post. I'm using

var el = document.getElementsByClassName("someclass");

to find the div, since FB doesn't use ID tags. I can get a value if i run the var but its not working with removeChild for some reason.

Ramesh
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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Uncaught TypeError: Cannot read property 'parentNode' of undefined

From Dev

$animate.addClass TypeError: Cannot read property 'parentNode' of undefined

From Dev

TypeError: Cannot read property 'child' of undefined

From Dev

TypeError: Cannot read property 'state' of undefined (Giving props through link)

From Dev

Angular services giving "TypeError: Cannot read property 'helloConsole' of undefined"

From Java

TypeError: Cannot read property 'then' of undefined

From Dev

TypeError: Cannot read property 'then' of undefined

From Dev

"TypeError: Cannot read property 'then' of undefined

From Dev

s.nTHead.parentNode == this || (s.nTFoot && s.nTFoot.parentNode == this) ) leads to Uncaught TypeError: Cannot read property parentNode of null

From Dev

cordova giving TypeError: Cannot read property 'DATA_URL' of undefined:68

From Dev

On Form Submit event object giving error: "TypeError: Cannot read property "0" from undefined."

From Dev

cordova giving TypeError: Cannot read property 'DATA_URL' of undefined:68

From Dev

TypeError: Cannot read property 'image' of undefined

From Dev

Uncaught TypeError: Cannot read property 'toLowerCase' of undefined

From Dev

Uncaught TypeError: Cannot read property 'substr' of undefined

From Dev

TypeError: Cannot read property 'jquery' of undefined

From Dev

Angular TypeError cannot read property 'then' of undefined

From Dev

TypeError: Cannot read property 'valid' of undefined

From Dev

Uncaught TypeError: Cannot read property 'createRouteFromReactElement' of undefined

From Dev

Uncaught TypeError: Cannot read property 'ajax' of undefined

From Dev

Uncaught TypeError: Cannot read property 'call' of undefined

From Dev

TypeError: Cannot read property 'defaultPrevented' of undefined

From Dev

Uncaught TypeError: Cannot read property 'createDocumentFragment' of undefined

From Dev

Uncaught TypeError: Cannot read property 'addMethod' of undefined

From Dev

Uncaught TypeError: Cannot read property 'draw' of undefined

From Java

Uncaught TypeError: Cannot read property 'top' of undefined

From Dev

Getting TypeError: Cannot read property 'query' of undefined

From Dev

TypeError: Cannot read property 'post' of undefined in Nodejs

From Dev

Node: TypeError: Cannot read property 'on' of undefined

Related Related

  1. 1

    Uncaught TypeError: Cannot read property 'parentNode' of undefined

  2. 2

    $animate.addClass TypeError: Cannot read property 'parentNode' of undefined

  3. 3

    TypeError: Cannot read property 'child' of undefined

  4. 4

    TypeError: Cannot read property 'state' of undefined (Giving props through link)

  5. 5

    Angular services giving "TypeError: Cannot read property 'helloConsole' of undefined"

  6. 6

    TypeError: Cannot read property 'then' of undefined

  7. 7

    TypeError: Cannot read property 'then' of undefined

  8. 8

    "TypeError: Cannot read property 'then' of undefined

  9. 9

    s.nTHead.parentNode == this || (s.nTFoot && s.nTFoot.parentNode == this) ) leads to Uncaught TypeError: Cannot read property parentNode of null

  10. 10

    cordova giving TypeError: Cannot read property 'DATA_URL' of undefined:68

  11. 11

    On Form Submit event object giving error: "TypeError: Cannot read property "0" from undefined."

  12. 12

    cordova giving TypeError: Cannot read property 'DATA_URL' of undefined:68

  13. 13

    TypeError: Cannot read property 'image' of undefined

  14. 14

    Uncaught TypeError: Cannot read property 'toLowerCase' of undefined

  15. 15

    Uncaught TypeError: Cannot read property 'substr' of undefined

  16. 16

    TypeError: Cannot read property 'jquery' of undefined

  17. 17

    Angular TypeError cannot read property 'then' of undefined

  18. 18

    TypeError: Cannot read property 'valid' of undefined

  19. 19

    Uncaught TypeError: Cannot read property 'createRouteFromReactElement' of undefined

  20. 20

    Uncaught TypeError: Cannot read property 'ajax' of undefined

  21. 21

    Uncaught TypeError: Cannot read property 'call' of undefined

  22. 22

    TypeError: Cannot read property 'defaultPrevented' of undefined

  23. 23

    Uncaught TypeError: Cannot read property 'createDocumentFragment' of undefined

  24. 24

    Uncaught TypeError: Cannot read property 'addMethod' of undefined

  25. 25

    Uncaught TypeError: Cannot read property 'draw' of undefined

  26. 26

    Uncaught TypeError: Cannot read property 'top' of undefined

  27. 27

    Getting TypeError: Cannot read property 'query' of undefined

  28. 28

    TypeError: Cannot read property 'post' of undefined in Nodejs

  29. 29

    Node: TypeError: Cannot read property 'on' of undefined

HotTag

Archive