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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:16:37+00:00 2026-06-17T09:16:37+00:00

I have the following JS script for a show/hide toggle. I kinda have to

  • 0

I have the following JS script for a show/hide toggle. I kinda have to keep it in this format because the elements it works on are a lot and formatted badly and it would be too much of a hassle to make it in jQuery.

As the title says, the “show” event is working while the “hide” is not. And since I’m a complete JS noob I was wondering it you could help me. Here’s the code:

function toggle(obj) {
  for (var  i = 0; i< 50; i++) {
    var name = 'q' + i;
    var inchide_obj=document.getElementById(obj);
    if (inchide_obj && inchide_obj.style && inchide_obj.style.display == "block") {
      inchide_obj.style.display = "none";
    }
  }
  var deschide_obj=document.getElementById(obj);
  if (deschide_obj && deschide_obj.style) {
    deschide_obj.style.display = "block";
    deschide_obj.focus();
  }
}

The html implies some blocks of texts each with its own class, q1, q2, etc. Thank you in advance for your help 🙂

  • 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-17T09:16:38+00:00Added an answer on June 17, 2026 at 9:16 am

    Your current code first tries to hide the element 50 times, and eventually shows it at the end, unconditionally. I believe you’re looking for this:

    function toggle(id) {
        var obj = document.getElementById(id);
        if (obj && obj.style) {
            if(obj.style.display != "block") {
                obj.style.display = "block";
            } else {
                obj.style.display = "none";
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script: $("tr.member_profile_comment_row_frame").mouseover(function () { $(this.element."img.member_profile_comment_show_delete_button").show(); }); $("tr.member_profile_comment_row_frame").mouseout(function () { $(this.element."img.member_profile_comment_show_delete_button").hide();
I have Divs show and hide (with an animation) using the following script (I
I have following script: $('.news ul li').hide(); $('.news ul li:first-child').show(); function Roller() { var
I have the following script which works fairly nicely to show when ajax stuff
I have the following jQuery <script type=text/javascript> jQuery(function(){ jQuery('.link1').click(function(){ jQuery('.hide-div').hide(); jQuery('.toggle1').show(); jQuery('#arrow').css({top: '0px'}); });
I have the following code to hide/show elements depending on what value is selected
Hey guys I have the following: $(.views).click(function() { $(this).(.views).show(); }); $(.closeviews).click(function () { $(this).(.closeviews).hide();
So I now have the following jquery to hide or show a textbox based
I have the following script which works almost perfectly thanks to Chris Moutray .
I have the following code where I want to show / hide different text

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.