0

Within using Javascript in html, i am having this error:

"Uncaught TypeError: Cannot read property 'parentElement' of undefined"

var item=document.getElementsByTagName("table");
item[1].parentElement.removeChild(item[1]);//<--- why doesn't this work?, it works in consol of broswer

structure of HTML is:

<body>
<div class="title">
    <h1>Shopping Cart</h1>
</div>
<table class="table-fill">
    <thead>


...rest of html document...

I know that item is a nodelist, which i can get access to the parent but when opening the html file it won't work. commenting out the error line and inputing it into the consol of the browser make it function.

NOTE:i have two tables in the html, one already placed in html file(as seen above) and one i am creating in javascript using document.write, hence the [1] position of the nodelist.

Rambus
  • 21
  • 2

0 Answers0