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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:27:00+00:00 2026-06-08T06:27:00+00:00

I am having some trouble using Javascript to change the class of a div

  • 0

I am having some trouble using Javascript to change the class of a div element. The method I am currently using (See code below) works in Chrome and Firefox but not IE8 (I haven’t tested IE9 but assume it either works already or will once ie8 does).

The curious part is that in ie8 when I am changing the class of an input element, it works. but changing the class of a div does nothing (class isn’t changed at all)

JavaScript

function switchTab(tab, button) {
    var divs = document.getElementsByName("tab-content");
    var d;
    for (counter=0; counter<divs.length; counter++) {
      d = divs[counter];
      if (d.id == tab)
        d.className = "members";
      else
        d.className = "members-hidden";
    }
    var buttons = document.getElementsByName("button");
    var bu;
    for (counter=0; counter<buttons.length; counter++) {
      bu = buttons[counter];
      if (bu.id == button)
        bu.className = "tab-active";
      else
        bu.className = "tab";
    }
    return false;

}

Relevant HTML Snippets

<div id="nav">
<ul class="membernav">
   <li><input id="ob" type="button" class="tab-active" name="button" onclick="return switchTab('officers', 'ob')" value="Officers"></li>
   <li><input id="pb" type="button" class="tab" name="button" onclick="return switchTab('partners', 'pb')" value="Partners"></li>
   <li><input id="mb" type="button" class="tab" name="button" onclick="return switchTab('managers', 'mb')" value="Managers"></li>
   <li><input id="ab" type="button" class="tab" name="button" onclick="return switchTab('associates', 'ab')" value="Associates"></li>
</ul>
</div>

and further down in HTML

<div id="tab-contents">
<div class="members" name="tab-content" id="officers">
   <!-- irrelevant content removed to save space -->
</div>

<div class="members-hidden" name="tab-content" id="partners">
  <!-- irrelevant content removed to save space -->
</div>

<div class="members-hidden" name="tab-content" id="managers">
   <!-- irrelevant content removed to save space -->
</div>

<div class="members-hidden" name="tab-content" id="associates">
   <!-- irrelevant content removed to save space -->
</div>
</div>

The classes on the buttons are successfully being switched to/from tab and tab-active.

but the divs aren’t being changed from members to/from members-hidden.

Have I made some silly mistake? because I change both the same way, why is one working and the other broken?

  • 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-08T06:27:03+00:00Added an answer on June 8, 2026 at 6:27 am

    This post answers your question: getElementsByName in IE7

    To summarize: IE does not support getting elements by name that do not support the name attribute by default. This is why your standard form input fields will work, but a div will not.

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

Sidebar

Related Questions

I'm having some trouble using the Element.getElementsByTagName method. With the following HTML: <p id=test>
I am having some trouble trying to checkout the BitSharp source code using SVN.
I'm having some trouble with some javascript. I'm using jQuery to dynamiclly add rows
I'm having some trouble with scoping in javascript. I'm using a jquery plugin to
I am using CodeCanyon's Price Calculator, and am having some Javascript trouble. The first
I am having some trouble using the pantheios logging library with boost::threads. It seems
I'm having some trouble using constraints correctly. I have three tables, 'item', 'store' and
I'm having some trouble using regular expression to get date in a string. Example
Basically having some trouble with using Hover to hide or show an item. The
I'm having some trouble with MySQLdb when using it in a CGI script. I'm

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.