Reputation: 63
I'm trying to set top using java script. I logged the top of the menu after adding top style, but it does not work.
How to style top using js??
Here is my codes
const top = (document.getElementById(element).offsetTop);
top
is a number not String
document.getElementById('contentMenu').style.top = top.toString();
console.log("menu" +document.getElementById('contentMenu').style.top); //output: menu
Upvotes: 0
Views: 374
Reputation: 2049
const top = document.getElementById(element).getBoundingClientRect().top;
document.getElementById('contentMenu').style.top = `${top}px`;
console.log(document.getElementById('contentMenu').style.top)
Upvotes: 1