Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

General Discussion

jQuery UI Theme Selector

Hi Everyone,

I figured this might be worth sharing, for anyone who's ever been interested in changing themes on-the-fly for a page.

What drove this demo was a desire to change themes with a simple menu selection. That led me down the path of trying to mess around with document.styleSheets, or other voodoo techniques; but, it turns out, it's a rather simple process to load an AJAX response into a style tag before the main content (at the top of body or bottom of head).

It's worth mentioning that I was unable to get jQuery icons to work - they don't like being AJAX'ed in, apparently. So, I'm using Font Awesome icons for each theme change - just the left and right arrows on the calendar.

If you have any questions or feedback, please feel free to post it below. I enjoy the interaction.

The Demo

All the best,

Robert

1 Answer

Very cool, favorited it! I've wondered before how this was done, this is a great example to learn from.

Super tiny nitpick -

.ui-datepicker-next,
.ui-datepicker-prev {
  cursor: pointer;
}

*Edited for a little better coverage over the buttons. Thanks for sharing!

Hey Justin,

Glad you liked it! I'm really bummed that I can't figure out a way to access the icons, so I scrapped them and cleaned up the code. Also, I went ahead and tested it locally, spinning up a server. By doing this, I can access the icons and it looks great.

If it works on an actual server environment over codepen, then that sounds like a proper solution to me. Glad you got it working!