Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jQuery Toggle Texts?

Status
Not open for further replies.

sconti11

Technical User
Jan 31, 2011
95
US
The following code is what I am using to hide/show:

Javascript:

jQuery('#slickbox3242').hide();
jQuery('#slickbox3243').hide();
jQuery('#slickbox3244').hide();


jQuery.fn.fadeToggle = function(speed, easing, callback) {
return this.animate({opacity: 'toggle'}, speed, easing, callback);
};

jQuery("a.slick-toggle").click(function () {
var id = jQuery(this).attr('id');
jQuery("#slickbox" + id).fadeToggle({
speed:200,
easing : "swing"
})
jQuery(this).text(jQuery(this).text() == 'Show Filters' ? 'Hide Filters' : 'Show Filters');
return false;

});

HTML:

<a href="#" id="3242" class="slick-toggle">Show Sales Org Filters</a>
<div id="slickbox3242" style="overflow:hidden;">Some Content</div>

<a href="#" id="3243" class="slick-toggle">Show Retail Filters</a>
<div id="slickbox3243" style="overflow:hidden;"> Some Content</div>

So what I need help with is how to change the text of the links after toggling. For example the initial state of the slickbox3243 is hidden and the text should be "Show Sales Org" and then when it is visible the text should be "Hide Sales Org"

Can someone assist me?
 
The following code solved it:

jQuery('a.slick-toggle').click(function() {
jQuery('#slickbox' + this.id).fadeToggle({speed: 200, easing: 'swing'}) ;
var text = jQuery(this).text();
jQuery(this).text(text.match(/Show.*/) ? text.replace(/Show/, 'Hide') : text.replace(/Hide/, 'Show'));
return false;
});

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top