Toggle text when link is clicked

html toggle button with text
toggle text jquery
toggle html jquery
jquery toggle
javascript toggle
jquery toggle add text
how to toggle between text in jquery
change text on click

I have the below code that toggles a div (called #extra) into view:

$('#more').click(function() {
    $('#extra').slideToggle('fast');
    return false;
});

My click function is this link:

<a href="#" id="more">More about us</a>

How do I get that 'More about us' text to change to read 'Less about us' when the #extra div is visible? When the same link is clicked to hide the div, I'd like the text of the link to change back to read 'More about us'.

Just toggle the text ?

$('#more').click(function() {
    $('#extra').slideToggle('fast');
    $('#more').text(function(_,txt) {
        var ret='';

        if ( txt == 'More about us' ) {
           ret = 'Less about us';
           $(this).css('background','url(link/to/image1.png)');
        }else{
           ret = 'More about us';
           $(this).css('background','url(link/to/image2.png)');
        }
        return ret;
    });
    return false;
});

How To Toggle Text, Learn how to toggle text with JavaScript. Toggle Text. Hello. Toggle Text of an Element Example. <button onclick="myFunction()">Click Me</button> Login Form Signup Form Checkout Form Contact Form Social Login Form Register Form Form with Icons Newsletter Stacked Form Responsive Form Popup Form Inline Form Clear Input Field Hide Number Arrows Copy Text to Clipboard Animated Search Search Button Fullscreen Search Input Field in Navbar Login Form in Navbar Custom Checkbox/Radio Custom Select Toggle Switch Check Checkbox Detect Caps Lock Trigger Button on Enter Password Validation Toggle Password Visibility Multiple Step Form Autocomplete

Use this code :

$('#more').click(function() {
    jQuery(this).text('less about us');
    if($('#extra').is(':visible')){
          jQuery(this).text('Less about us');
    }else{
          jQuery(this).text('More about us');
    }
    $('#extra').slideToggle('fast');
    return false;
});

Here is the demo : http://jsfiddle.net/AAFaY/

How to Toggle Text Inside an Element on Click Using jQuery, You can use the jQuery click() method in combination with the text() method to replace or toggle the text inside an element such as a link (i.e. an anchor <a> )  It will inject into the link the text that is in the content property value. When you first come to the page it displays [View More] when clicked it expands and then displays [View Less] for the link, click again and it collapses the expanded content and once again the link is back to saying [View More].

Try this

$('#more').click(function() {
    var more = $(this);
    $('#extra').slideToggle('fast', function(){
        more.html(s.text() == 'More about us' ? 'Less about us' : 'More about us');
    });
    return false;
});

Demo

Toggle Text, When Hiding or Showing Div using onclick, on the same time and same click you can change the text of button or link depend on action? Using toggle method  When the user clicks the mouse button, the hyperlink is activated, and then the Click event occurs. Selects an item in a combo box or list box, either by pressing the arrow keys and then pressing the Enter key or by clicking the mouse button. Presses Spacebar when a command button, check box, option button, or toggle button has the focus.

Yes, for this Dinesh's solution is probably most eficient end elegant in jQuery, for hure

$(document).ready(function() {   
    $('#more').click(function() {
        var s = $(this);
            $('#extra').slideToggle('fast', function() {
                s.html(s.text() == 'More..' ? 'Less..' : 'More..');
            });
            return false;
    });
});
#wrapp {
  height: 38vh;
  width: 40vw;
  margin: 50px 50px;
  left: 10%;
  background-color: blue;
  position: absolute;
}
#wrapp #more {
  display: inline-block;
  padding: 5px;
  background: yellow;
}  
#extra {
  height: 100px;
  width: 250px;
  position: relative;
  margin: 1.2vh auto;
}
#extra p {
  position: relative;
  color: red;
  text-align: center;
  vertical-align: center;
  padding-top: 3.6vh;
  font-size: 2.5em;
  font-weight: bold;  
}
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <link rel="stylesheet" type="text/css" href="css/main.css"> 
        <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
        <script type="text/javascript" src="js/main.js"></script>
    <body>
        <div id="wrapp">
            <header>
                <h1>Heading...</h1>
            </header>        
           
            <a href="#" id="more">Less..</a>                
            <div id="extra"><p>Whatewer...</p></div>      
            
        </div>
    </body>

How to toggle text on click using jQuery, In this lesson, you will hide your clock, then add a link that if clicked, will display the getElementById('clockButton'); // now toggle the clock and the button text,  So, there’s a link that says “click to read more” or something like that. When you click on it, the div appears (which I’ve been able to achieve already by including the display:none; tag) and at the same time the div appears, the “click to read more” link disappears

$(document).ready(function() {   
    $('#more').click(function() {
        var s = $(this);
            $('#extra').slideToggle('fast', function() {
                s.html(s.text() == 'More..' ? 'Less..' : 'More..');
            });
            return false;
    });
});
#wrapp {
  height: 38vh;
  width: 40vw;
  margin: 50px 50px;
  left: 10%;
  background-color: blue;
  position: absolute;
}
#wrapp #more {
  display: inline-block;
  padding: 5px;
  background: yellow;
}  
#extra {
  height: 100px;
  width: 250px;
  position: relative;
  margin: 1.2vh auto;
}
#extra p {
  position: relative;
  color: red;
  text-align: center;
  vertical-align: center;
  padding-top: 3.6vh;
  font-size: 2.5em;
  font-weight: bold;  
}
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <link rel="stylesheet" type="text/css" href="css/main.css"> 
        <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
        <script type="text/javascript" src="js/main.js"></script>
    <body>
        <div id="wrapp">
            <header>
                <h1>Heading...</h1>
            </header>        
           
            <a href="#" id="more">Less..</a>                
            <div id="extra"><p>Whatewer...</p></div>      
            
        </div>
    </body>

WebD2: Using Javascript to Hide and Show Content, The .toggle() method binds a handler for the click event, so the rules outlined for the so links will not be followed and buttons will not be clicked if .toggle() has  You can use the jQuery click() method in combination with the text() method to replace or toggle the text inside an element such as a link (i.e. an anchor <a>), <div> or <button> element dynamically using the jQuery. Let's try out an example to see how this works:

.toggle(), <div class="tumble bounce">Some text.</div>. The second time we toggle the sad class. Examples: Toggle the class 'highlight' when a paragraph is clicked. 1. In this tutorial, I’ll show you how to toggle a Divi section, row, or module when you click on a button. This tutorial is a minor variation of a tutorial I found on creaweb2b.com called Custom Toggle Section In Divi. The Example. Click the button below to reveal a row containing some text, an image, and a video.

.toggleClass(), This can be done by using a href tag inside your div either enclosing text or an jQuery Mobile How to toggle text inside and element on click using jQuery. In any GUI design, the command button is the most important and most often used control. Buttons with Save, Open, OK, Yes, No and Cancel etc. as caption are familiar to any computer user. In PyQt API, the QPushButton class object presents a button which when clicked can be programmed to invoke a certain function.

Jquery change link text onclick, Toggle the visibility of content across your project with a few classes and our Float · Image replacement · Position · Screenreaders · Sizing · Spacing · Text Click the buttons below to show and hide another element via class changes: You can use a link with the href attribute, or a button with the data-target attribute. For shorter text, avoid narrow command buttons by using a minimum button width of 120px. For longer text, avoid wide command buttons by limiting text to a maximum length of 26 characters. If the button's text content is dynamic (that is, it is localized), consider how the button will be resized and what will happen to controls around it.