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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:53:51+00:00 2026-06-11T08:53:51+00:00

EDIT: Ive edited my code a little thanks to Alexander’s advice, but im still

  • 0

EDIT:
Ive edited my code a little thanks to Alexander’s advice, but im still getting the problem of the contents of the div not showing, ive looked up proper closing and cant see where else or if i need to add it anywhere else in the code. My update question is, what am i missing for this to work? Thanks

I have a table which is generated from a query, in this table there is a div, i need this div to show/hide onclick, now i have a working show/hide javascript (shown below) but this only works for 1 div.

how do i modify this so that my divs with id’s generated from my database ($id) can all be shown/hidden seperatly?

javascript:

  <script language="javascript">
    function toggle(id) {
       var ele = document.getElementById(id);
       var text = document.getElementById(id);
                 if(ele.style.display == "block") {
                 ele.style.display = "none";
                 text.innerHTML = "show";
     }
     else {
        ele.style.display = "block";
        text.innerHTML = "hide";
     } 
     } 
     </script>

html:

    Info: <a id='$id' href='javascript:toggle(\"$id\");'>show</a>
          <div id='$id' style='display: none'></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-06-11T08:53:52+00:00Added an answer on June 11, 2026 at 8:53 am

    in your generated HTML you can pass id value to your toggle() function so resulting HTML code will look like

    Info: <a id='$id' href='javascript:toggle("$id");'>show</a>
          <div id='$id' style='display: none'></div>
    

    javascript

    function toggle(id) {
           var ele = document.getElementById(id);
           var text = document.getElementById(id);
                     if(ele.style.display == "block") {
                     ele.style.display = "none";
                     text.innerHTML = "show";
         }
         else {
            ele.style.display = "block";
            text.innerHTML = "hide";
         } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, thanks for your help. Here's my situation: I'm trying to edit the code
EDIT: The code below has been edited to show the correct solution to the
Edit: I've edited the sample to better resemble the problem I have, now the
EDIT: I've altered the code to now read: View code: <h3>Your Orders:</h3> <table class=order-items>
EDIT: I've found what's causing the issue, but I don't know why and I
I have a problem with the code below. Compiler says incompatible types, java.lang.object[][] required
Hey, I've got this nice little piece of code, much like all the other
Edit: I thought about a possible solution, but I made another question as it
I've looked at a number of questions but still can't quite figure this out.
[EDIT]Whoops there was a mistake in the code, and now all the responses to

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.