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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:45:56+00:00 2026-06-09T14:45:56+00:00

I have two toggle divs that have same class name. When i click one

  • 0

I have two toggle divs that have same class name. When i click one of them, the plus symbol on the right side is not replacing with the minus symbol unless i click both of them.

http://jsfiddle.net/adige72/rxW3H/

html:

<div class="collapseTitle">Open 1<div class="symbol">&nbsp</div></div>
<div class="collapseContent">Content 1</div>


<div class="collapseTitle">Open 2<div class="symbol">&nbsp</div></div>
<div class="collapseContent">Content 2</div>

js:

var $coll = $('.collapseTitle');

$coll.click(function() {
    $(this).nextUntil('.collapseTitle').toggle('fast', callbackFn);
        function callbackFn(){
            $('.collapseContent').is(":hidden") ? $coll.find('.symbol').css({'background-position': '0 50%'}) : $coll.find('.symbol').css({'background-position': '-36px 50%'});
        }

$(this).toggleClass("expanded collapsed");


});

$coll.addClass('expanded').click();

Thanks in advance.

  • 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-09T14:45:58+00:00Added an answer on June 9, 2026 at 2:45 pm

    Try this.

    var $coll = $('.collapseTitle');
    
    $coll.click(function() {
        var $this = $(this);
        $(this).nextUntil('.collapseTitle').toggle('fast', function() {
            $this.next('.collapseContent').is(":hidden") ? $this.find('.symbol').css({
                'background-position': '0 50%'
            }) : $this.find('.symbol').css({
                'background-position': '-36px 50%'
            });
        });
        $this.toggleClass("expanded collapsed");
    });
    
    $coll.addClass('expanded').click();​
    

    http://jsfiddle.net/wirey00/rxW3H/1/

    I fixed the following

    $(this).nextUntil('.collapseTitle').toggle('fast', callbackFn);  // <-- just put the callback function here
            function callbackFn(){
              //  this is checking both .collapseContent.. you need to start from the current clicked .collapseTitle
                $('.collapseContent').is(":hidden") ?  $coll.find('.symbol').css({'background-position': '0 50%'}) : $coll.find('.symbol').css({'background-position': '-36px 50%'});
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some HTML that I need to toggle between two structures - one
Have two UIBarButtonItems want to make it as one UIBarButtonItem and toggle between them
I have two divs that I want to show one and hide the other
I have two classes (MVC view model) which inherits from one abstract base class.
Ok so i have a div that acts as a background for two divs(filled
(Jquery) I have two divs that I'm toggling back and forth (show and hide)
I have two toggle buttons that I want to link together so that pressing
I have a TD that contains two divs. The first div contains text and
I have two elements that shouldn't be active at the same time, so when
So I have a list of divs that appear in a vertical order. Two

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.