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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:53:02+00:00 2026-05-18T03:53:02+00:00

I have a var in js which holds a click action. This action is

  • 0

I have a var in js which holds a click action. This action is bound to a few different divs:

<div class="clickable"><div class="hidden">inner content 1</div></div>

<div class="clickable"><div class="hidden">inner content 2</div></div>

<div class="clickable"><div class="hidden">inner content 3</div></div>

The js looks like so:

$(document).ready(function(){

var clicker = function(){

    $('.hidden').slideUp();

    $(this).children('.hidden').slideDown();

    $(this).unbind('click',clicker);
}


$('.clickable').bind('click',clicker);


});

The above code basically works. If i click a div.clickable it shows the hidden content. If I click another div.clickable, it hides the content I was just looking at and reveals another one. The problem however is that because of that unbind function inside ‘clicker’ anything I click loses its clicker functionality. I did this because the hidden content has clickable stuff, and anything I now click inside the hidden content triggers off ‘clicker’ again.

Whats the more intelligent approach to this without using the accordion plugins?

How can I check to see if a div has been bound to a function, and if not, rebind it or something of the sort? All I am looking for is to rebind the div.clickable to ‘clicker’ once its been closed ie another div.clickable .hidden is being looked at.

  • 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-05-18T03:53:02+00:00Added an answer on May 18, 2026 at 3:53 am

    You can just exclude the one you’re clicking on in the .slideUp(), like this:

    $(document).ready(function(){
      $('.clickable').click(function(){
        $('.hidden').not($(this).children()).slideUp();
        $(this).children('.hidden:hidden').slideDown();
      });
    });
    

    By using .not() we’re excluding the current element in the .hidden ones to hide, and when showing children restricting it to only :hidden elements means we won’t re-slide any that are already visible.

    Another way to re-write it a bit more plainly is:

    $(function(){
      $('.clickable').click(function(){
        $('.clickable').not(this).children('.hidden').slideUp();
        $(this).children('.hidden:hidden').slideDown();
      });
    });
    

    Or, if they all .clickable elements are siblings:

    $(function(){
      $('.clickable').click(function(){
        $(this).children('.hidden:hidden').slideDown()
         .end().siblings('.clickable').children('.hidden').slideUp();
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string array variable called 'myAttachmentArray[]' which holds different figures like this:
var PageLoad = true; I have a file named properties.js which holds this value
I have an Array var cars = [2,3,..] which holds a few integers. I've
I have a nested oredered list which i m animating using this code... var
I have this string of numbers var array = 1,6,2,9,5 which is retrieved from
I have created a class which holds three classes as properties: public class Feeds
In my js I have a var in which I have stored innerHTML. The
I have the following var id='123'; newDiv.innerHTML = <a href=\#\ onclick=\ TestFunction('+id+', false);\></a>; Which
I have a query which works fine var queryItems = rawQuery.ObsDataResultList.AsQueryable().Where(Name = @0 AND
I have 3 MC on stage which are all alpha=0 var mcArray:Array = [mc1,mc2,mc3];

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.