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

110
Views
Javascript mutation observer adressing an element within a <li>

Im using a mutation observer to observe the changes that happen to an <ul> element. when observing, i get the following output:

<li class="rt__body-row full flex gc-07 rt__body-row--odd">
<span class="rt__row-left short">48,359.50</span>
<span class="rt__row-center">0.063</span>
<span class="rt__row-right">01:57:44</span>
</li>

Now i want to write an if statement about the second spans text (0.063). How do I adress the second span in javascript? Im pretty new to programming and below is my code:

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

window.setTimeout(obser1, 1700);

Below is my manifest file:

  "name": "Bybit orderbook color",
  "version": "1.1",
  "manifest_version": 2,

  "content_scripts": [
    {
      "matches": [ "https://www.bybit.com/trade/usdt/BTCUSDT" ],
      "css": [ "Style.css" ],
      "run_at": "document_idle",
      "js": [ "background.js" ]

    }

  ],

  "permissions": [ "activeTab" ]


}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming mutation.addedNodes[0] is an html collection, you could do

const vals = [...mutation.addedNodes[0].querySelectorAll("span")].map(span => span.textContent);

If a string you can do

const fragment = document.createElement("div");
fragment.innerHMTL = mutation.addedNodes[0];
const vals = [...fragment.querySelectorAll("span")].map(span => span.textContent);
about 4 years ago · Juan Pablo Isaza Report
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!