Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8891469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:45:15+00:00 2026-06-14T22:45:15+00:00

I am working on some functionality to show a div containing some text when

  • 0

I am working on some functionality to show a div containing some text when a user clicks on a link.

The link initially displays the text ‘show +’ and then when the div is revealed this text changes to ‘hide -‘. Code is below:

JQUERY

    <script>
    $(document).ready(function() {
    $('p.link + div').hide();
    $('p.link a').prepend('<span>info +</span> ');

    $('p.link a').click(function(e) {
     var vis = $(this).parent().next().toggle().is(':visible');
     $(this).find('span').text(vis ? 'hide -' : 'info +');
     e.preventDefault();
    });
    });
    </script>

HTML

    <p class="link"><a href="#" class="show-hide"> </a></p>

    <div class="info">

    <p>Some sample text to show and hide</p>

    </div> <!-- info -->

This is all working fine but then I decided rather then an immediate show / hide, it would be nice to gradually reveal the text by adding a speed to the toggle. I therefore amended the following line:

JQUERY

    var vis = $(this).parent().next().toggle("slow").is(':visible');

This gives me the transition effect I want but now the link text is not changing. It still initially displays as ‘info +’ but from there on after, regardless of whether or not the div is displayed or not, the link text reads ‘hide -‘.

I assume this is because somehow the code is always seeing the div as being displayed even when it is not but I am unsure of how to fix this.

Any help would be appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:45:19+00:00Added an answer on June 14, 2026 at 10:45 pm

    Use the callback argument of toggle to execute your statement after the transition is done, rather than trying to execute it immediately after.

    var span = $(this).find('span');
    $(this).parent().next().toggle("slow", function() {
      span.text($(this).is(":visible") ? 'hide -' : 'info +');
    });
    

    JSFiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on some functionality for an e-commerce where by a user clicks
I need to load 15 records initially and then when the user clicks on
I want some hide/show functionality with my div tag. I am using below code
So my code has been working fine, and I was added some extra functionality
I am working on converting the functionality of some JSP pages to GWT. I
Whilst working on some generally horrible Javascript code this morning, I came across the
I just upgraded to Eclipse Indigo. It appears that some working set functionality is
I am working on a PHP application and missing some of the functionality that
Currently I'm working on a website where I'd like to show some toolstips for
I'm working on implementing some Chrome-like tab functionality in an app and am having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.