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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:36:35+00:00 2026-06-06T13:36:35+00:00

So I have a web page where you can select text boxes and close

  • 0

So I have a web page where you can select text boxes and close them by clicking the background or the boxes again:

http://hashtag.ly/#NASCAR

So I’ve got some code that will add or remove classes based on what is clicked:

$('li').click(function(){
    _this = $(this)
    if (_this.hasClass('active')) {
        //Close it if you clicked on that's already open
        _this.removeClass('active')
    } else if ($('li.active').length !== 0) {
        //close one and open another one you clicked
        _this.siblings().removeClass('active')
        _this.siblings().bind('webkitTransitionEnd oTransitionEnd transitionend',function(){
            _this.addClass('active');
        });
    } else {
        //open the first one
        _this.addClass('active');
    }

});

//Close when clicking the background
$('#close').click(function(){
    $('.active').removeClass('active')
});

The issue: When you open a box and click it again it’s supposed to close itself, like the first if statement says. But if you switch between text boxes 3 times (utilizing the seconds if statement), and try to close the third text box, it just reopens itself over and over again. Any clue on why it does this?

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-06T13:36:39+00:00Added an answer on June 6, 2026 at 1:36 pm

    Got it figured out…

    The transition event handler doesn’t unbind even if you’re in a different if statement. Did a little reading, moved the .bind() and .unbind() to .on() and .off() as suggested by the creators of jQuery and added the off statement to the end of the on statement’s function.

    Here’s the code:

    $('li').click(function(){
        _this = $(this)
        if (_this.hasClass('active')) {
            //Close it if you clicked on that's already open
            _this.removeClass('active')
        } else if ($('li.active').length !== 0) {
            //close one and open another one you clicked
            _this.siblings().removeClass('active')
            _this.siblings().on('webkitTransitionEnd oTransitionEnd transitionend',function(){
                _this.addClass('active');
                _this.siblings().off('webkitTransitionEnd oTransitionEnd transitionend');
            });
        } else {
            //open the first one
            _this.addClass('active');
        }
    
    });
    
    //Close when clicking the background
    $('#close').click(function(){
        $('.active').removeClass('active')
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webpage where users can look for clients and select them. After
How can i set default home page in asp web.config file. i have already
I have a CascadingDropDown on an ASP.NET page. Now, the prompt text is Select
I have a SELECT element in a web page, and I'd like it to
I have a web page below to explorer, as you can see, it is
I have a web page with one input text for the barcode content and
I have an asp.net web page with a simple search text box that returns
Background I have a page on my ASP.NET MVC web app for users to
I have a table on my web page that have checkboxes on them. I
I have made this webpage, you can check it out here http://www.bettingtowin.net/webcam.html I have

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.