1

I'm trying to add a child node using node-html-parser from this answer

my html file looks like this:

...

 <tbody>
    <tr></tr>
   ...
 </tbody>
    

and node.js app:

const parse = require('node-html-parser').parse;

...

  const doc = parse(fs.readFileSync('./myfile.html','utf8'));
  doc.querySelector("tbody").appendChild("<tr></tr>");

but it's giving an error:

Cannot create property 'parentNode' on string '<tr></tr>'
cak3_lover
  • 1,440
  • 5
  • 26
  • can you add your HTML, It seems the parsing is an issue. Have you validated the HTML? – Apoorva Chikara Feb 21 '22 at 14:47
  • @ApoorvaChikara the html is too big to add here so I added the key part, but I have validated it – cak3_lover Feb 21 '22 at 15:26
  • This error comes when you try to add something to a string. It means the parsing is not done properly. check [this](https://stackoverflow.com/questions/41510186/cannot-create-property-on-string). – Apoorva Chikara Feb 21 '22 at 15:28

0 Answers0