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

144
Views
¿Cómo puedo agregar un número a un Span ID javascipt?

Tengo una página web HTML que obtiene un número de un javascript externo usando esto:

 <span id="numl"></span>

pero quiero agregar el número 10 al número generado, ¿cómo puedo hacer esto? Por ejemplo, el código anterior obtiene el número "8", pero en lugar de mostrar "8", debe agregarle 10, que sería igual a "18". "

soy nuevo en javascript y no se como hacerlo

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

0

El siguiente código debe incrementar el número en diez.

Para resolver el problema del tiempo, puede usar un observador de mutación para cambiar el número tan pronto como se cambie.

 //source: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/observe // identify an element to observe const elementToObserve = document.getElementById("num1"); //global variable to monitor changecount window.changeCount = 0; // create a new instance of `MutationObserver` named `observer`, // passing it a callback function const observer = new MutationObserver(function() { if(window.changeCount == 0) //so it wont recursively increment by 10 { element = document.getElementById("num1");//get Element element.innerText = parseInt(element.innerText) + 10; //increment innerText by 10 } window.changeCount = window.changeCount + 1; //increment change count by one }); // call `observe()` on that MutationObserver instance, // passing it the element to observe, and the options object observer.observe(elementToObserve, {subtree: true, childList: true});

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!