HTMLCollection returning null

I have already looked at other stackoverflow posts and none of them fix my error.

Trying to get the divs inside the outer div with class name "CodeMirror-code"

I’m building a chrome extension that directly modifies the html content of a specific webpage and when I call

const variable = document.getElementsByClassName('CodeMirror-code');


console.log("Length:", variable.length);

the output is: this

Now, when I try to call the first item of HTML collection like


this returns undefined or null

Other solutions says that you should surround the code in window.onload function in order for the DOM elements to be loaded in.
I did this, and there was no change.
Is there any way I can fix this error?

This is what is inside the HTML collection

133 thoughts on “HTMLCollection returning null”

  1. Its like you read my thoughts! You appear
    to know so much approximately this, such as you wrote the book in it or
    something. I feel that you simply can do with a few p.c.

    to pressure the message home a bit, however instead of that, this is great blog.

    A great read. I’ll definitely be back.

  2. Its like you read my mind! You seem to know so much about this, like you
    wrote the book in it or something. I think that you can do with some pics to drive the message home a bit, but instead of
    that, this is great blog. A fantastic read. I will definitely be back.

  3. First off I would like to say excellent blog!
    I had a quick question in which I’d like to ask if you do not mind.
    I was curious to know how you center yourself and clear your head before writing.
    I have had a tough time clearing my thoughts in getting my thoughts
    out there. I truly do take pleasure in writing however it
    just seems like the first 10 to 15 minutes tend to
    be wasted simply just trying to figure out how to begin. Any recommendations or hints?
    Appreciate it!

  4. Pretty nice post. I just stumbled upon your blog and wanted to say that
    I have really enjoyed browsing your blog posts.
    In any case I’ll be subscribing to your feed and I hope you write
    again very soon!

  5. I believe everything wrote made a bunch of sense.

    But, think about this, suppose you were to create a killer headline?
    I mean, I don’t wish to tell you how to run your website,
    however what if you added something that makes people desire
    more? I mean HTMLCollection returning null – JavaScript
    Help is kinda plain. You could peek at Yahoo’s front page and watch
    how they create news headlines to get people interested.

    You might add a related video or a related picture or two
    to grab readers excited about everything’ve got to say.
    Just my opinion, it would bring your posts a little

  6. Hi there! I could have sworn I’ve been to
    this website before but after browsing through some of the post
    I realized it’s new to me. Anyhow, I’m definitely delighted I found it and I’ll
    be bookmarking and checking back often!

  7. I have been surfing online more than three hours today, yet I never
    found any interesting article like yours.
    It is pretty worth enough for me. In my view, if all site owners and bloggers
    made good content as you did, the web will be a lot more useful than ever before.


Leave a Comment