Chapter 8. Improving Navigation

Links make the Web go around. Without the instant access to information provided by linking from page to page and site to site, the Web wouldn’t have gotten very far. In fact, it wouldn’t be a web at all. Since links are one of the most common and powerful pieces of HTML, it’s only natural that there are lots of JavaScript techniques for enhancing how links work. In this chapter, you’ll learn the basics of using JavaScript to control links, and how to open links in new windows and in windows within a page. In addition, you’ll learn how to make links more usable by creating larger link targets and navigation bars with multiple levels of menus.

You undoubtedly know a lot about links already. After all, they’re the heart of the Web, and the humble <a> tag is one of the first pieces of HTML a Web designer learns. Adding JavaScript to a page can turn a basic link into a supercharged gateway of interactivity…but only if you know how to use JavaScript to control your links. Once you’ve got the basics, later sections of this chapter will give you real-world techniques for controlling links with JavaScript.

To do anything with a link on a Web page, you must first select it. You can select all of the links on a page, just one, or a particular group of related links—for example, links that are grouped together in the same part of a page, or that share a certain characteristic such as external links that point to other ...

Get JavaScript: The Missing Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.