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

172
Vistas
How to get a control or a box created in memory but not render it on a page in javascript?

I am trying to build a solution where I need to make certain calculations on a label with certain text in it. However, I don't want to render that label on the page. Once, the calculations are made, the label can be discarded.

Is it possible in JavaScript to create such a label in the memory for calculations and not render it on the page? I don't want to render even a hidden control, as even that would need some space and modification on the web page.

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

0


You will need to append the element to the DOM if you want to do calculations based on the rendered size of the element. Here's a way to do that without affecting the layout of your page:

const hiddenLabel = document.createElement("span");

hiddenLabel.innerHTML = "Some Text";

Object.assign(hiddenLabel.style, {
  position: "absolute", // removes element from document flow
  visibility: "hidden", // element invisible, but layout still computed
});

document.body.appendChild(hiddenLabel);

// inspect dimensions of the rendered element.
console.log(hiddenLabel.getBoundingClientRect().width);

This particular example might be useful if, for example, you're trying to resize an input field based on the length of the input.

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