Skip to main content

Bug Tracker

Side navigation

#1092 closed feature (wontfix)

Opened March 31, 2007 02:53PM UTC

Closed December 05, 2009 02:57AM UTC

Last modified October 15, 2010 01:58AM UTC

ToggleText function requested

Reported by: frontier Owned by:
Priority: major Milestone: 1.1.4
Component: core Version: 1.1.3
Keywords: Cc:
Blocked by: Blocking:
Description

There are lots of other useful toggle functions in JQuery, I think one for Text is needed also. Thanks :)

Attachments (0)
Change History (7)

Changed April 27, 2007 10:21PM UTC by john comment:1

resolution: → wontfix
status: newclosed
type: enhancementfeature

I'm not entirely sure what you're requesting, specifically - but this sounds like something that could be easily duplicated otherwise.

jQuery.fn.textToggle = function(){
  return this.each(function(){
    if ( !this.oldValue ) {
      this.oldValue = jQuery(this).text();
      jQuery(this).text('');
    } else
      jQuery(this).text( this.oldValue );
  });
};

Changed July 16, 2007 02:14AM UTC by frontier comment:2

resolution: wontfix
status: closedreopened

how do I use that? sorry I'm not a JS guru

Changed July 21, 2007 01:03AM UTC by john comment:3

component: ajaxcore
milestone: 1.1.31.1.4
resolution: → wontfix
status: reopenedclosed
version: 1.1.21.1.3

You would include that in your page, then you would call it like so:

  $("#myelem").textToggle();

Changed August 10, 2007 09:49PM UTC by rfsean comment:4

resolution: wontfix
status: closedreopened

The solution posted only works once, since the variable is defined on DocumentReady. This is unacceptable, as toggle(Function even, Function odd) will toggle functions ad infinitum. Unfortunately, the following does not work:

$(.class).click(function() {
  $(.class).toggle(function() {
    $(this).text('to');},
  function() {
    $(this).text('fro');}
  );
});

This is what I assume the OP is trying to accomplish, as I am trying to accomplish the same.

Example usage is toggling of an element with a text-based link, having text switch between "open" and "close", "show" and "hide", etc.

Changed September 23, 2008 08:23PM UTC by sgh445 comment:5

jQuery.fn.toggleText = function(a, b) {
	return this.each(function() {
		jQuery(this).text(jQuery(this).text() == a ? b : a);
	});
};

Changed December 05, 2009 02:57AM UTC by john comment:6

resolution: → wontfix
status: reopenedclosed

We're not looking to land this at the time being.

Changed October 15, 2010 01:58AM UTC by dwaynecharrington@gmail.com comment:7

I just encountered a situation where such a function being in the jQuery core would have been a lifesaver and saved a whole lot of extra code / writing a plugin.

Think of the following scenario:

You have a container div and inside you have a header and a body div. The sole purpose is to allow you to toggle the body sections visibility (collapsible sections).

What happens when you want to show and hide a section and want a link within the header to change accordingly? Show more and Show less for example? You have to write the above code in, jQuery should have this by default.

Please consider adding this.