Skip to content
Advertisement

change footer size by id

I am trying to run a function that changes the margin-top size according to what is being displayed. However, it doesn’t seem to be working?

JavaScript

also tried this

JavaScript

Thank you

Advertisement

Answer

document.getElementById returns the element (if it exists) or null, not a boolean (true/false).

You can simply do if(heading) { ... } as your condition.

Here’s a snippet based on your code: https://codepen.io/29b6/pen/XWZVqWx

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement