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

135
Views
JS node styles don't get applied if in a if block

Neither style top nor bottom is applied. How can I fix this?

let btn = document.createElement("button");
btn.textContent = "Button";
btn.style.position = "fixed";
if (this.anchorBottom) {
    btn.style.bottom = this.y;
    console.log(true)
}
else {
    btn.style.top = this.y;
}
btn.style.right = 0;
document.body.appendChild(btn);

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Provide a unit as well.

let btn = document.createElement("button");
btn.style.position = "fixed";
if (this.anchorBottom) {
  btn.style.bottom = `${this.y}px`;
  console.log(true)
} else {
  btn.style.top = `${this.y}px`;
}
btn.style.right = '0px';
document.body.appendChild(btn);

Remember, you're not limited to only using px values.

about 4 years ago · Santiago Trujillo 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!