Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
How can I check if text content on page changed?

I want to check if the text content in the var cart changes its on this page: https://www.supremenewyork.com/shop/all

let cart = document.getElementById('items-count').textContent;

console.log(cart);
cart.addEventListener('change', function() {
 console.log("cart");
 window.location.replace("http://stackoverflow.com");
});

I get this error

Uncaught TypeError: cart.addEventListener is not a function at chrome-extension://ljhadajgdcijdfoopfbkjibfebkilieh/supreme.js:11:6

The script starts when I enter the page.

I already tried to Monitor it with a while loop like in the following code but then the website freezes and I cant use it anymore until the var change

let carted = 0
let cart = document.getElementById('items-count').textContent;
while (carted < 1 ) {
console.log(cart);
if (cart.length > 2) {
    cart ++;
    window.location.replace("http://stackoverflow.com");
    }
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Because you are trying to add an event listener to your element's textContent, not to your element, and you can't do that. Just do this

let cart = document.getElementById('items-count');

console.log(cart);
cart.addEventListener('change', function() {
 console.log(`cart content has changed — ${cart.textContent}`);
 window.location.replace("http://stackoverflow.com");
});
about 4 years ago · Juan Pablo Isaza Report

0

If you want to add a listener, you can't do it to textContent.

let cart = document.getElementById('items-count'); //.textContent

console.log(cart);
cart.addEventListener('change', function() {
 console.log("cart");
 window.location.replace("http://stackoverflow.com");
});

If you need that value, you can store it on another variable:

var content = cart.textContent
about 4 years ago · Juan Pablo Isaza Report

0

You could

var item = document.getElementById('items-count');
item.addEventListener("change", DoStuff);
function DoStuff(){
//do what do you want to do.
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!