Ask coding questions

← Back to all posts
Chrome Extension: Unexpected HTML Page Behavior
Smart0ne (725)

In the repl attached to this post, there's a chrome extension. When you install it, there's a button that you can click, and I intended it to increase the counter by one. However, it stays at 0 no matter how many times I click the button, but I'm not sure what's wrong with the code. Can someone correct it, and tell me what went wrong?

Note: To install it, first export repl, and go to chrome://extensions. Turn on "developer mode" and click "load unpacked". Select the directory with the code, and then the chrome extension is there.

ChezCoder (1588)

What happened here?

document.counter.innerHTML = counter_number;

Change it to this:

counter.innerHTML = counter_number;

Also i suggest you use textContent instead of innerHTML

counter.textContent = counter_number;


textContent changes the text of the element. If you did element.textContent = "<h1>CODE</h1>", that would set the physical text of the element to <h1>CODE</h1>.

innerHTML changes the HTML of the element. If you did element.innerHTML = "<h1>CODE</h1>", that would add a new <h1> tag to the HTML of the element.

Smart0ne (725)

@ChezCoder Even after switching, the counter doesn't update. :/