question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

is it possible to select and get html comments?

See original GitHub issue

i am searching for a node html parser which make it possible to get not only DOM nodes but html comments too in any way. is this possible`?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
harrynewsomecommented, Apr 1, 2019

I can confirm that you can access the comments like so in older versions of Cheerio:

var $comments = $("*").contents().filter(function () {
    return this.nodeType === 8;
});

$comments.each(function(){
    // read the existing comment
    console.log(this.data);

    // change it to something else
    this.data = "something else";
});

What versions?

Seems to be working for me in "cheerio": "^1.0.0-rc.2"

2reactions
MCTaylor17commented, Dec 7, 2017

I can confirm that you can access the comments like so in older versions of Cheerio:

var $comments = $("*").contents().filter(function () {
    return this.nodeType === 8;
});

$comments.each(function(){
    // read the existing comment
    console.log(this.data);

    // change it to something else
    this.data = "something else";
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Selecting HTML comments with jQuery - Stack Overflow
Selecting HTML comments with jQuery - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.
Read more >
HTML Comments - W3Schools
HTML comments are not displayed in the browser, but they can help document your HTML source code. HTML Comment Tag. You can add...
Read more >
How to show HTML comments with JavaScript
Comments don't show up in your HTML (as in any language that has comments) but, you can display them on the page for...
Read more >
HTML Comment – How to Comment Out a Line or Tag in HTML
For adding multi-line comments, select and highlight all the text or tags you want to comment out and hold down the two keys...
Read more >
The HTML Comment Tag: Here's How To Use It In Your Code »
You will be able to see this text. You can even comment out things in a sentence. Another thing you can do is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found