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

171
Views
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 answers
Answer question

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