0

I've been trying to use MutationObserver. I can get it to report if any element has been added to the DOM, but I can't reference these elements. I need to apply certain functions to them.

Let's say I have this HTML:

<div id="main">
Some Links
 <a href="www.123.com" class="myLink">Link 1</a>
 <a href="www.456.com" class="myLink">Link 2</a>
 <a href="www.789.com" class="myLink">Link 3</a>
</div>

New links may be added to this DIV element when I scroll. What I need is to get these new link elements and reference them in Javascript.

Note that it's not the exact tree. It's possibly much more nested, not so basic. But the myLink classes are there.

Performance is a slight worry, compatibility is not.

  • a good example of observer in this answer https://stackoverflow.com/questions/20420577/detect-added-element-to-dom-with-mutation-observer – Liquidchrome Aug 13 '20 at 15:54
  • @Liquidchrome That doesn't help me to get the new elements as variables or in an array, in any format that I can reference them with. I can already get it to report if any element has been added to the DOM. – Ufuk Sarp Selçok Aug 14 '20 at 13:54

0 Answers0