Bug Tracker

Ticket #1092 (closed feature: wontfix)

Opened 9 years ago

Last modified 5 years ago

ToggleText function requested

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


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

Change History

comment:1 Changed 9 years ago by john

  • Status changed from new to closed
  • Type changed from enhancement to feature
  • Resolution set to wontfix

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();
    } else
      jQuery(this).text( this.oldValue );

comment:2 Changed 8 years ago by frontier

  • Status changed from closed to reopened
  • Resolution wontfix deleted

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

comment:3 Changed 8 years ago by john

  • Status changed from reopened to closed
  • Resolution set to wontfix
  • Version changed from 1.1.2 to 1.1.3
  • Component changed from ajax to core
  • Milestone changed from 1.1.3 to 1.1.4

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


comment:4 Changed 8 years ago by rfsean

  • Status changed from closed to reopened
  • Resolution wontfix deleted

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() {
  function() {

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.

comment:5 Changed 7 years ago by sgh445

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

comment:6 Changed 6 years ago by john

  • Status changed from reopened to closed
  • Resolution set to wontfix

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

comment:7 Changed 5 years ago by dwaynecharrington@…

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.

Note: See TracTickets for help on using tickets.