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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:20:02+00:00 2026-06-17T11:20:02+00:00

http://jsfiddle.net/9UQwM/1/ the script removes class from the elements in an alternating pattern, most importantly

  • 0

http://jsfiddle.net/9UQwM/1/

the script removes class from the elements in an alternating pattern,

most importantly why?

and what can be done to fix the problem?

Object.prototype.removeClass = function (class_name) {
    if (this.length) {
        for (i = 0; i < this.length; i++) {
            this[i].classList.remove(class_name);
        }
    }
}
document.getElementsByClassName("test").removeClass("test");
  • 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-17T11:20:04+00:00Added an answer on June 17, 2026 at 11:20 am

    Because when you delete, the next index moves down one. Loop in the opposite direction.

    for (var i = this.length - 1; i >= 0; i--) { ... }
    

    http://jsfiddle.net/9UQwM/2/

    Using a while loop might bring more into it

    Object.prototype.removeClass = function(class_name) {
        if (this.length) {
            while(this.length>0) {
                console.log(this.length);
                this[0].classList.remove(class_name);
            }
        }
    }
    document.getElementsByClassName("test").removeClass("test");
    

    The output would be 7,6,5,4,3,2,1

    http://jsfiddle.net/9UQwM/4/

    So this is updated when you remove the class

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

Sidebar

Related Questions

http://jsfiddle.net/borayeris/sb9Ju/4/ Here is my script. How can I stop fading out if mouse is
http://jsfiddle.net/GGsEt/3/ Works on firefox HTML <ul> <li class="lib_undefined"> <span class="hidden_toggle"> <a href="/">Test</a> </span> </li>
http://jsfiddle.net/Zyjwb/5/ How can I display actual names of owners , based on the specified
http://jsfiddle.net/DaJWC/ i can't figure out how to make one of the links reverse so
http://jsfiddle.net/2N854/ html: <img alt=test width=100 height=100> javascript: alert($('img').height()); On most browsers (chrome), the alert
http://jsfiddle.net/D6be5/ HTML <table class=example border=1> <tr> <td> <label>Enter text</label> <textarea>Enter text</textarea> </td> </tr> <tr
http://jsfiddle.net/nicktheandroid/6BAfH/1/ The list-elements are sorted accordingly by the number in their span. Why is
http://jsfiddle.net/motocomdigital/c8Mey/1/ I'm using a twitter script which i'm binding a function to get the
http://jsfiddle.net/nicktheandroid/SsfpG/ I don't understand why these inline elements are causing the paragraph to stop
http://jsfiddle.net/VTD9P/2/ $(button).click(function(){ $(body).append('<div class=vidminclose>X</div>'); }); $(.vidminclose).click(function(){ $(this).remove(); }); ​ ​why is it when i

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.