document.getElementById() is probably one of the most useful things in web development with JavaScript! You can use it to change attributes, change the style, change almost everything about an HTML element! The argument(in the parantheses) has to be a string, whether you set a variable with the string of 'box' or just put that in the argument, you always have to follow that rule.
Now when I first learned this term, I didn't like it because I didn't understand what it meant, and I may not be the only one out there who didn't either, so I'll tell you! What you can do with this, is that it gives you access to whatever you want in your HTML document, (or JavaScript, but that's way ahead into the future), and you are getting the element, by the ID you set in your HTML document! They are other things like this, but we'll just worry about ID right now!
Now, when you want to edit an element, you need to set a variable with it, kind of like this
var box = document.getElementById('box');
Or you can be a little bit more line consuming, and do...
var boxName = 'box';
var box = document.getElementById(boxName);
YOU ARE READING
JavaScript for Newbies
Non-FictionThis is a step by step tutorial book on how to program in JavaScript. From beginner to Expert!
