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

182
Vistas
JavaScript if statement basedon class of mutation observer records

I'm pretty new to programming. I'm using a mutation observer to observe changes to an element. below is what i get in my console after observing a <ul> element.

<li class="rt__body-row full flex gc-07">
<span class="rt__row-left short">50,660.50</span>
<span class="rt__row-center">0.001</span>
<span class="rt__row-right">14:18:19</span>
</li>

and

<li class="rt__body-row full flex gc-07 rt__body-row--odd">
<span class="rt__row-left short">50,660.50</span>
<span class="icon iconfont icon-arrow"></span>
<span class="rt__row-center">0.002</span>
<span class="rt__row-right">14:18:19</span>
</li>

as you can see it gives me two different <li>s and i need to manipulate the spans based on the <li> class. below is my JS code:

function obser1() {
    const trades = document.querySelector('.scrollbar-dark');
    const observer = new MutationObserver(function (mutations) {
        mutations.forEach(function (mutation) {
            if (mutation.addedNodes.length) {
                const vals = [...mutation.addedNodes[0].querySelectorAll("span")].map(span => span.textContent);
                console.log(mutation.addedNodes[0]);
                console.log(vals);
            }
        })
    });
    console.log("obs1");
    observer.observe(trades, {
        childList: true,
        subtree: true,
        attributes: true,
        characterData: true
    })
    console.log("observed");
}

window.setTimeout(obser1, 1700);

I have tried the following:

var lines = [...mutation.addedNodes[0].querySelectorAll("li")];
 if (lines.classList.contains("rt__body-row--odd")){
   console.log("odd");
  }

but its not working.

about 4 years ago · Juan Pablo Isaza
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