Javascript Styles


Don’t make the same mistake as me. While staring at my code today and convinced that everything was written out correctly, I was completely puzzled as to why nothing was changing despite the fact everything seemed to be present. Can you see what’s wrong though?

var container = document.getElementById("#container");
    container.backgroundPosition = "20% 50%";

I’d forgotten a pretty crucial part though I hadn’t realised it at first.

var container = document.getElementById("#container");
    container.style.backgroundPosition = "20% 50%";

Oops. Well, I’ll definitely remember this next time since I spent almost half an hour puzzling over it the first time. What a silly mistake to make.