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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:37:28+00:00 2026-06-15T04:37:28+00:00

<div class=buttons> <a class=showSingle target=1>Click 1</a> <a class=showSingle target=2>Click 2</a> <a class=showSingle target=3>Click 3</a>

  • 0
<div class="buttons">
<a  class="showSingle" target="1">Click 1</a>
<a  class="showSingle" target="2">Click 2</a>
<a  class="showSingle" target="3">Click 3</a>
<a  class="showSingle" target="4">Click 4</a>
</div>

<div id="div1" class="targetDiv">Results from click 1</div>
<div id="div2" class="targetDiv">Results from click 2</div>
<div id="div3" class="targetDiv">Results from click 3</div>
<div id="div4" class="targetDiv">Results from click 4</div>​

jQuery(function(){
        jQuery('.showSingle').click(function(){
              jQuery('.targetDiv').hide();
              jQuery('#div'+$(this).attr('target')).show();
        });
});

​

I’ve found a great deal of ways to do this but can’t seem to get it to work for the way I have it set up. I need the .targetDiv to hide when you click anywhere on the page other other than when you’re clicking .showSingle or inside the .targetDiv box.

http://jsfiddle.net/XwN2L/1063/

  • 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-15T04:37:29+00:00Added an answer on June 15, 2026 at 4:37 am

    Update: I bound it to html instead of body to fix clicking outside of the content area.

    Here is your function, it triggers whenever the body of the page is clicked:

    jQuery('html').click(function(){
        if( !jQuery(event.target).hasClass('targetDiv') ){
            jQuery('.targetDiv').hide();
        }
    });
    

    ​
    Then, we will also need to add

    e.stopPropagation();
    e.preventDefault();
    

    To your first function prevent double actions. (Also, don’t forget to add e to your function arguments)

    Here is a fiddle for it: – http://jsfiddle.net/XwN2L/1065

    Best of luck to you.

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

Sidebar

Related Questions

I have this HTML structure <div class=buttons> <button data-icon=ui-icon-disk class=save>Save1</button> <button data-icon=ui-icon-check class=ok>OK1</button> <button
JQuery-ui will generate a div with a calendar-div class. Sadly this div is no
When I click the class red I want to delete this entire div. My
If i want to click the .img class then the div class=hide pane pane_right
<div class = 'buttons'> <button type=submit class=regular name=save> <img src=elephant.png alt=/> Memory </button> </div>
i have some radio buttons with class = active <div id=radioset1> <input type=radio class=active
I have multiple buttons on my page with the same class. When I click
I am very new to jQuery. Below is part of my code <div class
I have a menu set up this way: <div id='top-navigation'> <ul> <li><a class='top-nav-button-unclicked' href='#'>SUBJECT</a></li>
I have a div class named switch control which has a div class named

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.