Change your Javascript to:
$('.more').click(function() { var s = $(this); var originaltext= s.text(); $('.more').text('More about us'); s.text(originaltext); s.html(s.text() == 'More about us' ? 'Less about us' : 'More about us'); });
What does he do:
- Save the
text current clicked range. - Change all ranges to "More about us."
- Change the current text to the original.
- Continue to work with normal functionality.
See the fiddle: " http://jsfiddle.net/HFcvH/35/ "
EDIT: This can also be done with .siblings() as follows:
$('.more').click(function() { var s = $(this); $(this).siblings().each(function() { $(this).text('More about us'); }); s.html(s.text() == 'More about us' ? 'Less about us' : 'More about us'); });
Explanation: This will repeat all the siblings of the current item and reset their text.
See the fiddle: " http://jsfiddle.net/ee24gcdj/1/ "
It can be further reduced with (thanks to Ted Nyberg for the info):
$(this).siblings().text('More about us')
Nikhil Batra
source share