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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:31:43+00:00 2026-05-22T23:31:43+00:00

In my HTML for my file I have a div with the id divNavyBox.

  • 0

In my HTML for my file I have a div with the id “divNavyBox.” The code is below.

<div id="divNavyBox" class="box" onmouseover="animated.doAnimation()"></div>

Note that once the mouse hovers over it, it executes the doAnimation() from var animated.

var animated = {

el : document.getElementById("divNavyBox"),

doAnimation : function() {
    if (el.className=="box") {

        el.className="boxAlt";
    }
    if (el.className=="boxAlt") {
        el.className="box";
    }

}

};  

I want it to switch between these two cs classes once the method doAnimation is executed. However, it doesn’t do anything. I put an alert statement inside of the if(el.className=”box” and it didn’t ring up as I executed the function, even though the class really IS box. The two CS classes that I want to be used are listed below:

.box {

    width: 100px;

    height: 100px;

    background-color: navy;

}
.boxAlt {
width: 100px;
height: 100px;  
background-color: red;
}

Why does the boolean statement el.className=”box” keep returning false?

  • 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-22T23:31:43+00:00Added an answer on May 22, 2026 at 11:31 pm

    here you assign boxAlt if current = box

    if (el.className=="box") {
        el.className="boxAlt";
    }
    

    here you switch back if current is boxAlt which is allways true if the class has been box from the beginning.

    if (el.className=="boxAlt") {
        el.className="box";
    }
    

    Change it to something like:

    doAnimation : function() {
        el.className = el.className == "box" ? "boxAlt" : "box";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single .html file that looks similar to the following: <div id=myPage
I have nav code like this in my HTML file: <div id="center_links"> <ul> <li><a
I have the following code in my file to load a div with HTML
I have this simple piece of HTML code: <div> <input type=file name=english-file /> </div>
I have the following HTML file: <div class=tituloD> </div> <div class=subtituloD> </div> <div class=puntosD>
If i have the following code in my html file <div id=div1> <script type=text/javascript>
I have the following HTML file: <!-- this is column 1 --> <div class=repairGuruBoxRC>
Hi everyone in my main html file, I have this div that some img
I have the following code snippet from a HTML file: <div id=rwImages_hidden style=display:none;> <img
I have this code in index.html file: $(function(){ $('a#link').live('click', function(e){ $(div#element).load(file.html); }); }); In

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.