课程: JavaScript Essential Training

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Solution: Create elements

Solution: Create elements

(lively music) - [Instructor] There are several ways of solving this challenge. I'll walk you through the one I think is most logical and it's also the most verbose one, which works well for our purposes 'cause then you can see exactly what's happening. I'll go down to create nav menu here and start off by creating a new nav element. So I'll create the outermost container that we'll be working with. I'll put it inside a new const called mainNav and I'll set it equal to document.createElement and specify the nav element. So now we have a nav element inside the dom. It's not attached anywhere yet, but we can now reference it and use it. Next, I want to append a class to the nav element. So I'll say mainNav.classlist.add and then main-navigation. Now the nav has a class. Next, I need to create an unordered list to place inside this new nav element. So I'll say const and give it a name, navList. Set it equal to…

内容