Style Sheet Switcher

One of the most powerful uses of JavaScript is the ability to modify, on the fly, which style sheet is being used. For example, you can offer your site’s visitors the ability to choose the style and size of the text on your site. Some people like to read tiny, sans-serif text that gets lots of words on the screen (Figure 15.10), while others prefer larger, serif text that’s a bit more readable (Figure 15.11). Now you can make both kinds of visitors happy. And to make it even more useful, this script also uses cookies to store the user’s choice for future visits.

Figure 15.10. Some visitors prefer to read smaller, sans-serif text that can get more text on the page.

Figure 15.11. Other visitors will be glad to choose ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition 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.