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

The Archive Base Latest Questions

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

I am looking to hide a number of DIVs based upon the specific text

  • 0

I am looking to hide a number of DIVs based upon the specific text of another DIV. My Javascript (below) isn’t working.

The HTML:

<div id="LEGEND">abAB</div>

<div id="small-a"></div> 
<div id="small-b"></div> 
<div id="big-a"></div> 
<div id="big-b"></div> 

If the LEGEND DIV contains the text a, then I want it to show only DIV small-a.
If the LEGEND DIV contains the text bA, then I want it to show only DIV small-b and big-a.

The Javascript:

<script>
window.onload = function ShowHide{

    if (document.getElementById('LEGEND').indexOf("a") > 0){
        document.getElementById('small-a').style.display = 'block';}
    if (document.getElementById('LEGEND').indexOf("b") > 0){
        document.getElementById('small-b').style.display = 'block';}
    if (document.getElementById('LEGEND').indexOf("A") > 0){
        document.getElementById('big-a').style.display = 'block';}
    if (document.getElementById('LEGEND').indexOf("a") > 0){
        document.getElementById('big-b').style.display = 'block';}    
</script>
  • 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-12T22:55:58+00:00Added an answer on May 12, 2026 at 10:55 pm

    You are forgetting a couple of things.

    • A function declaration should be like this

      function functionName(args) {
      }

    • You have to hide the divs using style.display = “none”

    Example:

    <div id="LEGEND">abB</div>
    
    <div id="small-a" style="display: none;">This is small-a</div> 
    <div id="small-b" style="display: none;">This is small-b</div> 
    <div id="big-a" style="display: none;">This is big-a</div> 
    <div id="big-b" style="display: none;">This is big-b</div>
    
    <script>
    function showElement(id) {
        document.getElementById(id).style.display = "block";
    }
    
    window.onload = function ShowHide() {
        var legend = document.getElementById("LEGEND").innerHTML;
    
        if(legend.indexOf("a") != -1) showElement("small-a");
        if(legend.indexOf("b") != -1) showElement("small-b");
        if(legend.indexOf("A") != -1) showElement("big-a");
        if(legend.indexOf("B") != -1) showElement("big-b");
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me with javascript that hides divs matching a specific random number?
I'm looking to create a select menu that shows and hide certain divs based
I am looking for a jQuery plug-in which will show / hide a div
I’m looking for an easy way to hide everything except a certain div and
I'm looking for some way to effectively hide inherited members. I have a library
I'm looking for a trick to hide the .dll extension of an isapi dll
I'm looking for a show/hide component, much like the toolbox from VS2010 and eclipse's
What I'm looking to do is hide only the popups that show what key
I'm looking for the easiest possible way to hide an UpdatePanel while waiting for
I am looking to format the datagridview so I can hide and format certain

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.