Time for action – adding navigation to sections of the page
Perform the following steps to add navigation to our weather forecast:
- Open up
scripts.js
. The first thing we want to do is create an unordered list to hold our navigation. After the animation code we wrote earlier, but still inside the document ready statement, add the following bit of code:var dotnav = $('<ul id="dotnav"></ul>');
First, we create a variable,
dotnav
. Recall that a variable is just a container. Inside this container, we're going to create a jQuery object that holds an unordered list with theid
attribute ofdotnav
. - Now that we've got our unordered list, the next thing we'll do is add it to our document. That's easy enough, just one short line of code:
var dotnav = $('<ul id="dotnav"></ul>'); $('body').append(dotnav);
We're selecting the
<body>
element of the document and appending our navigation to the end...