Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
How to use .contains on childList mutation?

I am using MutationObserver and want to check a class selector on target.className but I get an error

Cannot read properties of undefined (reading 'contains')

so I looked at classList's prototype and it has .contains method and I did the following target.classList.prototype.contains("OverlayWrapper") and I still get the same error.

I don't understand why I am getting this error as I am trying to check for a partial className .

Edit: I have added a snapshot of the consoleenter image description here

Edit: I have made an example for the code, it is the bare minimum where I am looking for a class that contains popUp__wrapper being added to the DOM. (an error will be in the console when we press the open button) jsfiddle

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Issues

  • mutation.addedNodes is an nodeList (collection of nodes). So obviously classList not exists in it.

  • Your class popUp__wrapper is suffixed with a an scxdxcfd. No class with exact name popUp__wrapper.

Solution

let wrapperEl = Array.from(mutation.addedNodes) // convert NodeList to array
      .filter(n => n.nodeType != Node.TEXT_NODE) // remove text nodes
      .find(n => n.matches('[class*=popUp__wrapper]')) // search for class

If you need to check popUp__wrapper available inside the node, use querySelector instead of matches

Demo

https://jsfiddle.net/aswinkumar863/qjeafxd8/20/

References

https://developer.mozilla.org/en-US/docs/Web/API/Element/matches

https://developer.mozilla.org/en-US/docs/Web/API/Text

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda