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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:17:12+00:00 2026-06-18T16:17:12+00:00

I am trying to change class name of two elements during onload. Here is

  • 0

I am trying to change class name of two elements during onload.

Here is my code for the same :

    var browserName=navigator.appName;
    var tfElem = document.getElementById("TTlExpct");
    var blTfElem = document.getElementById("BTLExpct");
    if (browserName=="Microsoft Internet Explorer")
    {
        tfElem.className ="pn-tf";
        blTfElem.className ="pn-tf active";
        }
    else
    {
        tfElem.setAttribute('class', 'pn-tf');
        blTfElem.setAttribute('class', 'pn-tf active');
        }

The else block takes care of the code if its not IE, in mozilla, this is working fine, class name is getting set.

Its not working in IE7 and IE8

and

in chrome, it works only if i reload the page again.

Any help will be appreciated .

  • 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-18T16:17:14+00:00Added an answer on June 18, 2026 at 4:17 pm

    There is a bug in the implementation of setAttribute in old versions of IE. In newer versions of IE that bug may be emulated if you do not use a Doctype that triggers standards mode.

    Replace:

    foo.setAttribute('class', value);
    

    With:

    foo.className = value;
    

    Do this everywhere. Don’t try to do browser detection. All browsers that support setAttribute('class', value) also support foo.className = value.

    The code in your question should be rewritten as:

    var tfElem = document.getElementById("TTlExpct");
    var blTfElem = document.getElementById("BTLExpct");
    tfElem.className ="pn-tf";
    blTfElem.className ="pn-tf active";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here two of my model classes: class DashboardVersion(models.Model): name = models.CharField(_(Dashboard name),max_length=100) description =
I am trying to change the class of a element with Javascript using the
I am trying to change the property type in interface implementation class using explicit
I am trying to access/change the properties of a class' Parent through Reflection. If
I'm trying to Show / Hide two elements based on a selection - a
I am trying to obtain the same files using Intersect method from two folders.
I have a movieclip with class myClass and no instance name. I'm trying to
I am trying to access and change a array from a different class file.
I am trying to change to class-based views in Django after an upgrade and
I'm trying change an input mask for textbox when the the check box has

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.