Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!