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>'
3
  • can you add your HTML, It seems the parsing is an issue. Have you validated the HTML? Commented Feb 21, 2022 at 14:47
  • @ApoorvaChikara the html is too big to add here so I added the key part, but I have validated it Commented Feb 21, 2022 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. Commented Feb 21, 2022 at 15:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.