Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.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);```

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading