Home > front end >  Traverse the label problem
Traverse the label problem

Time:09-18


Could you tell me why the same code, will have different results,
I type the code in the js file:
 
Var a_s=document. GetElementsByClassName (" nav_1 ");
The console. The log (a_s);
The console. The log (a_s. Length);
The console. The log (a_s [1]);

The output is:

How is this to return a responsibility excuse me?

CodePudding user response:

Please answer, thank you very much,

CodePudding user response:

The code in the HTML page is from the top to the bottom of the page phase while parsing, at this time in this page element finished parsing, access,
To put the script at the bottom of page body tag, or use the window. The onl oad event can trigger after parsing is complete (page),
  • Related