uzairfarooq / arrive

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

Watch for multiple classes #71

Closed qayyumabro closed 5 years ago

qayyumabro commented 5 years ago

Hi Uzair, it's a nice library that you have developed, Unfortunately, I just found it today and needed it badly in the projects that I already developed. Your library could have saved a lot of hours :).

I just checked it for an element which contains multiple class names, but it didn't fire. Am I doing it right?

$(document).leave(".jfk-butterBar .jfk-butterBar-info .jfk-butterBar-shown", function() { var $removedElem = $(this); alert('loaded'); })

uzairfarooq commented 5 years ago

Hey @qayyumabro. Nice to see that it helped. Unfortunately, nested classes are not supported in leave (they are supported in arrive function though). You can do something like this:

$(document).leave(".jfk-butterBar-shown", function() {
  // additional checks here to make sure it's right element
})

From the documentation: The first argument to leave must not be a descendent or child selector i.e. you cannot pass .page .test-elem, instead, pass .test-elem. It's because of a limitation in MutationObserver's api.

qayyumabro commented 5 years ago

Thanks Uzair, that makes sense.