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 8458387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:04:03+00:00 2026-06-10T13:04:03+00:00

I am using Andy Langton’s show/hide jQuery code but looks like the code has

  • 0

I am using Andy Langton’s show/hide jQuery code but looks like the code has some glitches when you use multiple toggles on the same page.

When using multiple Show/Hide it would not toggle to the correct word. It seemed to track the last toggle overall rather than the setting for each link. In other words, if I clicked ‘More’ on the first article, it would change to ‘Less’. If I pressed ‘More’ on the next article without hiding the previous, it would stay at ‘More’, and if I try and hide the first article now, that word remained ‘Less’.

This is the code I am using:

// Andy Langton's show/hide/mini-accordion - updated 23/11/2009
// Latest version @ http://andylangton.co.uk/jquery-show-hide
$(document).ready(function() {

    // choose text for the show/hide link - can contain HTML (e.g. an image)
    var showText='MORE ↓';
    var hideText='LESS ↑';

    // initialise the visibility check
    var is_visible = false;

    // append show/hide links to the element directly preceding the element with a class of "toggle"
    $('.toggle').prev('.moree').append('<a href="#" class="toggleLink">'+showText+'</a>');

    // hide all of the elements with a class of 'toggle'
    $('.toggle').hide();

    // capture clicks on the toggle links
    $('a.toggleLink').click(function() {

    // switch visibility
    is_visible = !is_visible;

    // change the link depending on whether the element is shown or hidden
    $(this).html( (!is_visible) ? showText : hideText);
    //$(this).html( ($(this).html() == hideText) ? showText : hideText);

    // toggle the display - uncomment the next line for a basic "accordion" style
    //$('.toggle').hide();$('a.toggleLink').html(showText);
    $(this).parent().next('.toggle').toggle('slow');

    // return false so any link destination is not followed
    return false;

    });
    });

Any help to fix this would be appreciated.

Marz

  • 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-10T13:04:04+00:00Added an answer on June 10, 2026 at 1:04 pm

    Problem in code is

    Use of same var is_visible to toggle elements.

    We have to check visibility of corresponding div every time we toggle the visibility of content.

        $(this).html( ($(this).parent().next('.toggle').is(":visible")) ? showText : hideText);
    

    See it in action

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

Sidebar

Related Questions

I'm using Andy Langton javascript to get my veiwport size. See link below if
I'm using sql to pull together a table like this: person flavour purchase andy
I'm using jQuery mobile and am launching a dialog like so: $.mobile.changePage('#someDiv', { role:
I'm trying to wrap div with specific html code but I'm having problem using
I am using embed.ly API, but when using example code i just get a
I recently tried to mirror some input within input(text) fields. Using String.fromCharCode(event.which) for instance,
I'm using the Fogbugz API (v6.0) to submit new cases from some error reporting
I have a web app, that also has an iPhone and Android app using
I'm using Selenium Java 2.0b3 . I have this code: ... WebDriver driver =
I have read some posts on this website about using drawInRect instead of the

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.