Sergei Basharov
Sergei Basharov

Reputation: 53938

Toggle content with jQuery

I have a link "Show More...". When I click it I toggle visibility of a div with details. I wonder if there is a simple beautiful way to toggle content of the link between "Show More..." and "Hide details" when the div toggle occurs?

Upvotes: 0

Views: 397

Answers (4)

DrPumpkinhead
DrPumpkinhead

Reputation: 23

You could change the content thats being displayed using CSS rules: http://jsfiddle.net/8G6fm/

I guess the advantage is if you want to style it further you can add to the styles (e.g using a background image of an arrow pointing left / down depending on whether it is open or not).

Upvotes: 0

Matthew Doyle
Matthew Doyle

Reputation: 1065

I've used this before with some success:

http://plugins.learningjquery.com/expander/index.html

Upvotes: 0

Zachary
Zachary

Reputation: 6532

If you just want to switch around text, here is a simple example in jQuery based on using a SPAN as a label.

$('#SpanLabel').html($('SpanLabel').text() == 'Show More...' ? 'Hide details' : 'Show More...');

Upvotes: 3

Related Questions