taoqf / node-html-parser

A very fast HTML parser, generating a simplified DOM, with basic element query support.
MIT License
1.11k stars 107 forks source link

Sample querying for id not working? #239

Closed vicmortelmans closed 1 year ago

vicmortelmans commented 1 year ago

Hi,

I'm trying to use node-html-parser (6.1.5) in a nodejs project.

It didn't work when querying for a class, so I tried the sample in the README, just entering the commands in VScode debug console, and while querying an element works, querying an id doesn't:

> root = HTMLParser.parse('<ul id="list"><li>Hello World</li></ul>');
<ul id="list"><li>Hello World</li></ul>
> root.querySelector('#list')
null
> root.querySelector('li')
<li>Hello World</li>

What's wrong?

Best regards, Vic

taoqf commented 1 year ago

https://github.com/taoqf/node-html-parser/commit/a439a96d3b7e934f13e5795f5d16ad4a2a10da3c I've add test for this issue and I believe this will work very well. Let me know if this still bothers you.