0

I'm using Mutation Observer with JS to observe the change on a button. When it changes I want to check for a conditional and then decide whether I should disable or enable the same button. When I test this logging either "enabled" or "disabled" on the console, it works, but when I add myButton.setAttribute('disabled', true); it seems to stop working and doesn't even log the message in the console. So I think maybe that is not the way to disable a button on a Mutation Observer.

I'm using a counter for my code to run only if the counter is under 10 because without it, it loops infinitely. That worked to stop the loop but it still doesn't disable the button.

  • No code no help. Complete the [Tour](https://stackoverflow.com/tour) and read ["How to Ask"](https://stackoverflow.com/help/how-to-ask). You should provide a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Marc Jan 28 '23 at 15:46
  • This maybe: https://stackoverflow.com/questions/3014649/how-to-disable-html-button-using-javascript – Moritz Ringler Jan 28 '23 at 16:12
  • may be you running into a problem with the Mutation Observer triggering the callback function multiple times, which is causing the infinite loop. –  Jan 28 '23 at 16:21

0 Answers0