.style.left="40%"; does not work in javascript

document.getElementById("buttonNextPage").style.left="40%"; does not work!


<footer id="buttonNextPage">
  <a href="#contact" class="button style2 down">More</a>


#buttonNextPage {
    position: absolute;
    bottom: 10px;
    left: 50%;



I don’t know where the problem is. Thank you for your help!

Hi there bfaist15,

and a warm welcome to these forums. :winky:

Your code, as presented, works OK for me.

This suggests that there must be something
else in the full code that is the problem. :shifty:


1 Like

I do not see where you add position: relative; You have to do that (to parent element) so the absolute positioned elemtent to work.

That’s not quite right as the absolute element will still work fine but takes its co-ordinates from the viewport (or nearest ancestor with position other than static applied). Of course usually you would need a parent with position:relative applied if you want to use the parent as the positioning context.

For the demo above it will not affect the problem the OP is trying to debug and as mentioned by coothead the code shown is working ok anyway.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.