S
SolidJS•14mo ago
Dikiy

How can you get the id of element body when its id is changed?

How can you get the id of body element when changing its id, is there any hooks or something like that?
6 Replies
deluksic
deluksic•14mo ago
You can sub to MutationObserver in createEffect https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
MDN Web Docs
MutationObserver - Web APIs | MDN
The MutationObserver interface provides the ability to watch for changes being made to the DOM tree. It is designed as a replacement for the older Mutation Events feature, which was part of the DOM3 Events specification.
deluksic
deluksic•14mo ago
Don't forget onCleanup
Grahf
Grahf•14mo ago
Would using a ref for the element be better?
deluksic
deluksic•14mo ago
How would you use a ref? You can just document.body in the effect
Dikiy
DikiyOP•14mo ago
Thanks for reminding me about oncleanup👍
Grahf
Grahf•14mo ago
Oh I thought it said element in the body

Did you find this page helpful?