Keith Walker4,820 Points
Selecting ID's with variables.
So I'm a bit confused as to what is happening when we call the elements from the html.
const myHeading = document.getElementById('myHeading');
now I assumed we were assigning the const variable myHeading to equal the element in the HTML with the ID of 'myHeading'. Then using this variable with the addEventListener method. Yet it doesn't seem to matter what the name of the const variable is. for instance I can say
const myHeadingIsSomethingElse = document.getElementById('myHeading');
and still use
What is the point of assigning the variables in this case? is it simply loading those elements to the JS? Do we actually call upon those variables anywhere else, or do we always use the id of the element from the html? Could you assign something else to that variable later in the code (considering you use let instead of const), and still have access to the the element?
Dario Bahena10,688 Points
// const whateverYouWantDoesntMatter = document.getElementById('myHeading'); // the dom item is now associated to the whateverYouWantDoesntMatter variable // by definition, variable means it can be anything within the rules of naming in js.