uzairfarooq / arrive

Watch for DOM elements creation and removal
MIT License
874 stars 99 forks source link

Feature request: respond to arrival of multiple elements #66

Open praxiq opened 6 years ago

praxiq commented 6 years ago

I'm writing code that should run when two specific elements both exist. They could be created in any order. I'd like to do something like this:

document.arrive(['.first', '.second'], function() { ... })

or perhaps this:

document.arrive({first: '.first', second:'.second'}, function() { 
  const first = this.first; 
  const second = this.second;
})

Any interest in adding this sort of thing, or is there a straightforward workaround?

uzairfarooq commented 6 years ago

Interesting. How would it behave in case of multiple .first, .second elements? With single element like this document.arrive('.elem', function() {}) it keeps on firing whenever an element is added to DOM.

jsabrooke commented 3 years ago

I wanted this too, but that's a good point @uzairfarooq! I guess at least in an initial implementation, it would only ever fire once? Might be a bit unclear though...

mattvb91 commented 2 years ago

Is there any way to achieve this? currently looking for exactly this too