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

  • Home
  • SEARCH
  • 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 8662127
In Process

The Archive Base Latest Questions

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

Basically I’m trying to find all the elements with a particular class name and

  • 0

Basically I’m trying to find all the elements with a particular class name and switch it to another. I have another function that switches this back to the original class name. Here’s my function that’s triggered with an onclick:

function showEventsAppliedTo() {
    var myObj = document.getElementsByClassName('notApplied');
    while (myObj.length >= 0) {
        myObj[0].className = 'mblListItem notAppliedOut';
    }
    AppliedToButton.set('style', 'display:none;');
    EventListingButton.set('style', 'display:block;');
}

I’m getting an error saying myObj[0] is undefined. Any idea why this is happening?

As a note, we’re using Dojo, hence the last line of the function. I know I could easily do this with jQuery, but we’re not using it and it doesn’t make sense to load another framework.

Thanks in advance for your help.

EDIT

Thanks to the help from Abhishek Mishra, I modified how I’m handling this loop and found a way to do it with JUST dojo, which is what I preferred. Here’s the code:

function listingClassToggle() {
    dojo.query(".notApplied").addClass("notAppliedOut");
    dojo.query(".notApplied").removeClass("notApplied");
}

Much simpler code and a lot lighter than my previous solution. Thanks for all your help. I hope this helps someone else.

  • 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-12T16:39:36+00:00Added an answer on June 12, 2026 at 4:39 pm

    Should just test for > 0 not >= 0. When the length is equal to zero, there’s no element zero.

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

Sidebar

Related Questions

basically I have a function that resizes elements accordingly with jquery triggering the function
Basically, I have a UIImageView that will loop through 8 PNGs over 0.5 seconds.
Basically from C++ FAQ I learned that: A virtual function allows derived classes to
Basically, I have a main page (parent page) with a link that opens up
Basically this function is meant to store the height value of the element that
Basically I have an IFRAME that contains a given page - I want to
Basically I have some simple code that does some things for files and I'm
Basically I have an iframe loaded that is accessed from the parent whenever it
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer

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.