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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:11:55+00:00 2026-05-12T11:11:55+00:00

I am wanting to use jquery to do a show/hide of a DIV from

  • 0

I am wanting to use jquery to do a show/hide of a DIV from a text link.

What makes it a little different from the examples I have found of this site so far is I need a generic way of doing it multiple times on 1 page and also able to use it sitewide on anypage.

It would be really nice if I can put the JS in seperate file that is included into the pages, so maybe it can be wrapped into a function?

Can someone help me here? For making it generic it could be where I assign a div that is shown/hidden with an id like id=”toggle-hide-1″ and just change the numbers in my page to make it a different show/hide area

I could just name the ID using a name that will make the function show/hide a div and to seperate it from other divs that show/hide on a page I could add a number to it.

below is partial code that will do a show/hide of a div on a link click but is not exactly what I need.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
<script type="text/javascript" >
$(function() { 
    $(".view-code").click(function(evt) {
        $(".tool_block, .view-code").toggle();
    }); 
});
</script>
<a href="#" class="view-code" >view code</a>
<a href="#" class="view-code"  style="display:none">hide code</a> <br  />

<div class="tool_block" style="display:none" >
this stuff is hidden until we choose to show it!
</div>
  • 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-12T11:11:55+00:00Added an answer on May 12, 2026 at 11:11 am

    The best approach is probably going to be something using custom attributes. If you markup your anchor with an attribute that tells the jquery which div to toggle, it will be easier to write generic code to do the work.

    Something like this:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
    <script type="text/javascript" >
    $(function() { 
        $(".view-code").click(function(evt) {
            var d = $(this).attr("toolDiv");
            $(".tool_block[toolDiv=" + d + "], .view-code[toolDiv=" + d + "]").toggle();
        }); 
    });
    </script>
    <a href="#" class="view-code" toolDiv="1" >view code</a>
    <a href="#" class="view-code" toolDiv="1" style="display:none">hide code</a> <br  />
    
    <div class="tool_block" toolDiv="1" style="display:none" >
    this stuff is hidden until we choose to show it!
    </div>
    

    Then give each of your anchor-div pairs a unique toolDiv value (doesn’t have to be a number).

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

Sidebar

Related Questions

I'm wanting to use the jquery dialog to open a modal dialog, and in
I am wanting to use the AJAX function via jQuery to return some data
I have a client that is wanting to have jquery.colorbox and wants the background
I'm wanting to loop an array of text. I was going to use .each()
I'm wanting to click a button and have the matching id name show. I
I am wanting to use jQuery to add the current browser window dimensions to
I'm wanting to use jQuery-UI on a page with multiple instances where some instances
I'm wanting to use jQuery to wrap a mailto: anchor around an email address,
I am wanting to use the Facebox plugin for JQuery but am having a
For some reason jquery's .hide() won't hide a div that contains a file input

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.