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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:28:04+00:00 2026-06-13T08:28:04+00:00

I am trying to get multiple elements, that are organised under 3 arrays tops,

  • 0

I am trying to get multiple elements, that are organised under 3 arrays “tops”, “bottoms”, “shoes”.

I know I can grab multiple objects using the

document.getElementsByClassName("class1 class2");

How do I change the style for each of those objects, my current code is: (I have tried both visibility and opacity, but it keep getting a uncaught type error because the document.getelements…. isn’t returning anything.

function filter() {
var this_id = event.target.id;
console.log(this_id);
if (this_id = "filtertops") {
    document.getElementsByClassName("a4 a7 a11 a12 a8").style.visibility="hidden"; //not tops
    document.getElementsByClassName("a1 a2 a3 a5 a9 a10 a14").style.visbility="visible"; // tops
    }
else if (this_id = "filterbottoms") {
    document.getElementsByClassName("a2 a3 a5 a10 a14 a8").style.opacity="0.4"; //not bottoms
    document.getElementsByClassName("a1 a4 a7 a9 a11 a12").style.opacity="1"; //bottoms
    }
else if (this_id = "filtershoes") {
    document.getElementsByClassName("a1 a2 a3 a4 a5 a7 a9 a10 a11 a12 14").style.opacity="0.4"; //not shoes
    document.getElementsByClassName("a8").style.opacity="1"; //shoes
    }

I tried assigning them to a variable as well and then a for loop to change the style of each object, but that didnt work either.

function filterbottoms() {
    var nonbottom = document.getElementsByClassName("a2 a3 a5 a10 a14 a8");
    var bottoms = document.getElementsByClassName("a1 a4 a7 a9 a11 a12");
    for (i in bottoms)
        {
            i.style.visibility='visible';
        }
    for (i in nonbottom)
        {
            i.style.visibility='hidden';
        } 

}
  • 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-13T08:28:05+00:00Added an answer on June 13, 2026 at 8:28 am

    You were close with the for loop:

    for (i in bottoms){
        bottoms[i].style.visibility='visible';
    }
    

    should <edit>but won’t</edit> work. On each iteration i is the next key, not the next value.

    But you should use a conventional for rather than a for..in:

    for (var i = 0; i < bottoms.length; i++){
        bottoms[i].style.visibility='visible';
    }
    

    EDIT: I recommended a conventional for loop because using for..in is generally not appropriate for arrays or array-like objects as (depending on the particular object) it will iterate over non-numeric properties. Joseph’s comment confirms that in this case a for..in will definitely not work for that reason.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get my query to grab multiple rows while returning the
I am currently trying to get multiple xml files into my xsl file to
I have a question about the JFileChooser in Swing. I'm trying to get multiple
In short: How do I access LocationManagerService.mProximityAlerts ? I'm trying to get multiple ProximityAlerts
I am trying to get a multiple upload library working for my Codeigniter based
I'm trying to get col1 values for certain multiple col2 values. For example: I
I am trying to get jquery validate to work on multiple fields. Reason being
I'm trying to call Get-WMIObject (gwmi) on multiple computers selected via Get-ADComputer as a
I'm trying to write a bash script that will let me download multiple web
I have multiple elements on a page that have matching classes. The classes are

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.