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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:15:48+00:00 2026-06-12T17:15:48+00:00

This is a stupid question, but i can’t figure it out, say i have

  • 0

This is a stupid question, but i can’t figure it out, say i have two divs:

<div class="one"></div>
<div class="two"></div>

Div one is a button, div two is a box.

Now when i click on div one div two should be visible (by default it isn’t)

And when i click on div one one more time div two disappears and so on…

Here is my code for that:

$(".one").live("click", function(){
    state = $(this).attr("state");

    if(state == "active"){
        $(this).attr("state", "inactive");
        $(".two").css("display", "none");
    }else{
        $(this).attr("state", "active");
        $(".two").css("display", "block");
    }
});

And now my problem is that i also want div two disappear when i click anywhere in my page so this is what i did:

$(document).click(function(){
     $(".one").attr("state", "inactive");
     $(".two").css("display", "none");
});

Now what happens is probably click event on document happens after the click on div and it doesn’t let me open box.

One solution that i know is to check if (event.target.className != "one") but i would really like to avoid that since in my real project i have a lot of other elements in that button so i would need to include all of them, and i would like to avoid that.

  • 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-12T17:15:49+00:00Added an answer on June 12, 2026 at 5:15 pm

    return false; from the bound .live() handler. You want to stop event propagation and that is the way to break the chain for live events (which have already bubbled).

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

Sidebar

Related Questions

Probably a stupid question but so far I can't figure this out... I have
this might question might sounds stupid, but I could'nt figure it out. How can
This sounds like a stupid question but i can't figure it out for the
This is probably a really stupid question but I can't figure this out. I
This may be a stupid question but I can't seem to figure this out.
I am sure this is a stupid question but I can't figure out how
I have a feeling this is a stupid question but I can't find the
This is a stupid question, but I can't work it out and it's beginning
Hopefully this isn't a stupid question but I can't seem to work out how
This may seem like a stupid Question but i have two cubes being rendered

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.