I looked at the source code of the Pinterest page and it seems that the comments are contained in a div with the attribute data-test-id with the value description-content-container.
Hey @hamdorable! To answer your question, you didn’t do anything wrong, it’s just that the snippet of code that you shared probably isn’t doing quite what you expected.
In it’s most basic form, a JavaScript file executes a series of commands from the top of the file to the bottom. In computer science terms, JavaScript is an imperative programming language. I’m assuming the JavaScript snippet you provided was included in a content script. If that’s the case, the snippet is probably being called while the page is loading, so the comment you’re trying to hide may not even be part of the document yet.
CSS, on the other hand, is a declarative programming language; rather than providing a series of commands that you want to execute, you declare what you want to happen and let the browser handle the process of figuring out when and where your style rules should be applied.
Hope that sheds a bit more light on why one approach worked as expected and the other didn’t!