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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:27:36+00:00 2026-05-17T17:27:36+00:00

i’m struggling with display/hide text using javascript here. Here is what i wanted to

  • 0

i’m struggling with display/hide text using javascript here.
Here is what i wanted to achieve like the picture below:
alt text

and the below is my javascript i’ve got:

function change_display(display)
{
    if(display.style.display=="none")
    {
        display.style.display="";
        }
        else
        {
        display.style.display="none";
        }
    }

Html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="Style_sheet.css" rel="stylesheet" type="text/css" />
<script src="Display text.js" type="text/javascript"></script>
</head>

<body onload="change_display(display)">
<div class="Body">
<div class="header">
<h1 id="head">Manage Components</h1>
<h3 id="select-system">Select System</h3>
</div>
<div class="side-nav">
<a href="javascript:change_display(display)">192.101 English A</a>
<div id="display"><a href="javascript:change_display(display)">&nbsp;&nbsp;Section 1:</a></div>
<div id="display">&nbsp;&nbsp;&nbsp;&nbsp;Topic 1:</div>
</div>

</div>

</body>
</html>

What i’ve got there doesn’t work. I don’t know how to get it to work

Although, i could display as text 1 but if i want to keep click and display downward, it won’t work.

Oh also, i want use css style with it as well, is there anyway i could do? cos i already use ID for javascript therefore, i can’t use ID again for css. I’ve tried to use “name” but doesn’t work at all.

Please help! Thanks in advance!

  • 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-17T17:27:37+00:00Added an answer on May 17, 2026 at 5:27 pm

    A couple of the obvious issues:

    you are calling change_display(display), but you have not created/filled a variable named display. you can’t have multiple elements with the same id. you can’t directly access an html element by id- you have to get a reference to it using the id.

    some minor things we’ll clean up right away:
    the call to change_display is not needed for body‘s load event. calling js from href is bad form.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link href="Style_sheet.css" rel="stylesheet" type="text/css" />
    <script src="Display text.js" type="text/javascript"></script>
    </head>
    
    <body >
    <div class="Body">
    <div class="header">
    <h1 id="head">Manage Components</h1>
    <h3 id="select-system">Select System</h3>
    </div>
    
    <div class="side-nav">
    
        <a href="#" onclick="change_display('eng_a'); return false;">192.101 English A</a>
    
        <div id="eng_a" style="padding-left: 20px;">
           <a href="#" onclick="change_display('eng_a_sec_1'); return false;">Section 1:</a>
    
           <div id="eng_a_sec_1" style="padding-left: 20px;">
              Topic 1:
           </div>
    
        </div>
    
    </div>
    
    </div>
    
    </body>
    </html
    

    javascript:

    function change_display(id)
    {
        // gets an html element by its unique id.
        var display = document.getElementById(id); 
    
        if(display.style.display=="none")
        {
            display.style.display="";
        }
        else
        {
            display.style.display="none";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.