The navbar won't resize on scroll, can anyone point out what I'm doing wrong? Thank you :)

https://codepen.io/noethix/pen/GYBaqK

There’s no getElementByTagName, only getElementsByTagName.

I have tried it also and it doesn’t work either…

It’s because now you’re getting a list of elements that have the nav tag. Grab the first one only :wink:

function scrollFunction() {
  if (document.body.scrollTop > 80 || document.documentElement.scrollTop > 80) {
    document.getElementsByTagName("nav")[0].style.padding = "15px 0px";
  } else {
    document.getElementsByTagName("nav")[0].style.padding = "30px 0px";
  }
}
1 Like

Thank you :slight_smile: