Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

nicholas maddren
nicholas maddren
12,793 Points

How can I change icon when toggle is pressed?

Hey guys I'm just wondering how I would go by changing a glyphicon when the toggle is active? So for example there is a plus at the moment but I would like a minus to appear when the toggle is open.

Here is an example: http://jsfiddle.net/DTcHh/848/

How would I achieve this?

Thanks, Nick :)

1 Answer

You probably want to do something like: .removeClass().addClass() on your glyphicon span.

With your example fiddle that would look something like: $(this).children('span')removeClass(glyphicon glyphicon-plus glyph-plus-toggle).addClass(glyphicon glyphicon-minus glyph-minus-toggle);

nicholas maddren
nicholas maddren
12,793 Points

Could you show me an example of how you would implement that? When I add it to the code the toggle breaks :(