O'Reilly logo

JavaScript® Bible, Seventh Edition by Paul Novitski, Danny Goodman, Tia Gustaff Rayl, Michael Morrison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 30. Link and Anchor Objects

IN THIS CHAPTER

  • Differences among link, anchor, and a element objects

  • Scripting a link to invoke a script function

  • Scripting a link to swap an image on mouse rollovers

The Web is based on the notion that the world's information can be strung together by way of the hyperlink—the clickable hunk of text or image that enables an inquisitive reader to navigate to a further explanation or related material. Of all the document objects you work with in JavaScript, the link is the one that makes that connection. Anchors provide guideposts to specific locations within documents.

As scriptable objects going back to the first scriptable browsers, links and anchors are comparatively simple devices. But this simplicity belies their significance in the entire scheme of the Web. Under script control, links can be far more powerful than mere tethers to locations on the Web.

In modern browsers, the notion of separating links and anchors as similar yet distinctly different objects begins to fade. The association of the word link with objects is potentially confused by the newer browsers' recognition of the link element (see Chapter 40, "HTML Directive Objects"), which has an entirely different purpose as a scriptable object. Taking the place of the anchor and link objects is an HTML element object representing the element created by the <a> tag. As an element object, the a element assumes all the properties, methods, and event handlers are associated with all HTML element ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required