javascript - getElementByTagName question -


i know if want find group of elements, getelementsbytagname method , returns nodelist. if looking tag name "body" , why need add [0] after ("body") element? there 1 body tag in html document.

 var body = document.getelementsbytagname("body")[0];  body.classname = "unreadable"; 

why cant write code without index[0] this

 var body = document.getelementsbytagname("body");  body.classname = "unreadable"; 

if write code class unreadable not added body tag ...why?

because document.getelementsbytagname allways returns nodelist. if want find easier way retrieve body can use document.body


Comments

Popular posts from this blog

actionscript 3 - TweenLite does not work with object -

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -

c# - Global Variables vs. ASP.NET Session State -