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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:37:06+00:00 2026-06-03T22:37:06+00:00

Here is my HTML and javascript code: HTML: <div id=common> Hi Welcome </div> <div>

  • 0

Here is my HTML and javascript code:

HTML:

<div id="common">
    Hi Welcome
</div>

<div>
    <a href="javascript:toggleDiv('customize');" >click here</a>
</div>

<div  id="customize">
    <form action="" method="post" id="MyForm">
        {%  form%}
    </form>
</div>

Javascript code:

<script>
    function toggleDiv(divId) {
        if ($("#"+divId).show()) {
            $("#common").hide();
        }
        else {
            $("#common").show();
        }
    }
</script>

If i click the link “Click here” one div id should be hide and another should be show and if i click it another time vice-versa process should be happened. i tried using this javascript but it’s not worked properly

  • 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-03T22:37:08+00:00Added an answer on June 3, 2026 at 10:37 pm

    You need to use :visible to check if the passed div is already visible. Try this:

    function toggleDiv(divId) {
        var $el = $("#" + divId);
        if ($el.is(":visible")) {
            $el.hide();
            $("#common").hide();
        }
        else {
            $el.show();
            $("#common").show();
        }
    }
    

    You should also change your code to use jQuery to attach you events instead of the clunky onclick attribute:

    <a href="#" id="link" data-rel="other-div">click here</a>
    
    $("#link").click(function(e) {
        e.preventDefault();
        toggleDiv($(this).data("other-div"));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to enable facebox jquery using javascript. here in normal html <a href=stairs.jpg
I have html like so: <div class=foo> (<a href=forum.example.com>forum</a>) <p> Some html here.... </div>
I have a html form where on button click, JavaScript function needs to start
please help me select c.. Here's the HTML code: <div id=a> <div id=b></div> <div
Here is my html code with javascript validations.... HTML elements are showing well javascript
I am writing a XML file into a HTML file using JavaScript. Here is
Here are the problem scripts: This is from the HTML file: <script type=text/javascript> var
Consider the following example: ( live demo here ) HTML: <div class=board> <div class=row>
I am trying to follow Trees tutorial at: http://cslibrary.stanford.edu/110/BinaryTrees.html Here is the code I
Here is my HTML: <tr> <td colspan=2 class=borderBottomCell> <div class=benefitInfo style=WIDTH: 99%! important;> <asp:DropDownList

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.