How to watch the content of a div?

I need to watch the content of a div on my “shop” page that is the number of items added to a cart. The content of this div is being populated from third-party javascript and only on one page of my site.

I need to take this value when it’s updated by the third-party script, and place it in another part of my html, in a separate component, that exists on every page. (currently the cart only shows on the shop page, but I want it to show in the header).

What is the best approach to do this?

I believe I will need to make an ajax call to the ‘shop’ page and check the innerHTML of the cart item count div, then populate that value. This allows me to pull it initially, but then I would still need to watch that value as people add items to the cart (only from the shop page).

Thank you for pointing me in the right direction.