Adrien Castagliola Adrien Castagliola - 1 year ago 88
Javascript Question

Is there an event to detect if an attribute is set in Javascript?

I want to execute a script when some data attribute are set. Attributes can be set AFTER the all page is loaded.

In that case the script doesn't execute.

<div data-id='' data-position=''></div>

But in that one, i want to execute it

<div data-id='3' data-position='67'></div>

Is it even possible ?

Answer Source

You can use MutationObserver to listen attribute change and act upon.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download