Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda