Question about CodePen's Javascript

Question about CodePen's Javascript
0

#1

So im about to start Tribute Page project soon, i went trough intro of CodePen, it wrote <h1>Hello World</h1> and after that in CSS it styled body’s colour and then in JavaScript it wrote:

document.getElementsByTagName("h1")[0].style.fontSize = "80px"; .

So im wondering what does this “[0]” mean inJS code it wrote?


#2

Didn’t you write this? If you just copied it from somewhere, you really don’t want to do that. It means creating a Frankenstein page that you don’t understand.

In answer to your question, getElementsByTagName() returns an array.


#3

document.getElementsByTagName() will get ALL of the tags by the name that is passed to it. In the example you gave, if there were seven H1 tags on the page, all of them would be gathered in a kind of array (it’s technically an HTML Collection).

[0] gives the first one.


#4

No i didnt write it, CodePen’s intro auto-wrote it. I did copy it, and i dont understand what you meant by Frankenstein page lol.


#5

I knew about tag stuff but i wondered what that 0 in that bracket does. Thanks.


#6

Before you start using JavaScript in your Tribute page project, you should probably wait until you have actually finished the Basic JavaScript section of Free Code Camp. This will enable you to understand what [0] means in the above code.


#7

It means it may look real but it’s just a reanimated braindead monster.


#8

I already have finnished it, but basics didnt cover what 0 means when used in document.getElementBy… code, i actually thought it could be counting from 0,1,2,3 etc… but i wanted to make sure what it was 100%.