How to monitor when the body 'data' attribute changes in jQuery?

javascript, jquery, jquery-events

Solution

`There is no reliable cross-browser way to receive an event when a DOM node attribute is changed. Some browsers support "DOM mutation events", but you shouldn't rely on them, and you may Google that phrase to learn about the ill-fated history of that technology.

If the slider control does not fire a custom event (I would think most modern ones do), then your best bet is to set up a `setInterval()` method to poll the value.

Problem

I have data-segment attribute in my body tag that is changed by a slider. I need to trigger a function based on the value of this, when it is changed. I'm not sure how to attach an event listener in this case though?

Original source