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

148
Vistas
How can i add number to a javascipt Span ID

I have an HTML webpage that gets a number from an external javascript using this:

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

but I want to add the number 10 to the generated number, how can I do this, for example, the code above gets number "8" but instead of showing "8" it should add 10 to it which would be equals to "18"

I'm new to javascript and don't know how to do this

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

0

The following code should increment the number by ten.

To resolve the timing issue you can use a Mutation Observer to change the number as soon as it is changed.

//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 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