getElementsByTagName()
has 2 great features: it is fast and it is live. But what if I want to get p strong
. Of course I could refine a selection using getElementsByTagName()
again but wouldn't I lose the live effect for the new p
tags?
Is there a way to turn querySelectorAll
into a live selector?
Or... is there a way to use getElementsByTagName()
and getElementsByClassName()
to create a function that works in a similar way (at least with descendants) as querySelectorAll
but being live?
Consider using mutation observers. Watch for
childList
withsubtree: true
. When the notification arrives, you can examine each added node withmatches
to see if it matches some selector.I don't think it is possible because subsequent changes of the DOM does not reflect in the NodeList object returned by the querySelectorAll() method.
Selectors-api W3C