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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:38:43+00:00 2026-05-28T20:38:43+00:00

I created a page to play around with the 960 Grid System, learn about

  • 0

I created a page to play around with the 960 Grid System, learn about div placement. There are up to four divs on the page. When a new grid size, pull or push value is selected from a dropdown, I need to remove the current class, i.e. grid_8, pull_5 or push_4, and add the newly selected class.

function alter_grid1(new_class_name){

   var old = document.getElementById('grid1');
   var classes = old.className.split(' ');
   var old_class_name = 'cessna';
   $.each(classes, function(){

        if(old_class_name == 'cessna' || old_class_name == null){
          old_class_name = this.match('/grid_1|grid_2|grid_3|grid_4|grid_5|grid_6|grid_7|grid_8|grid_9|grid_10|grid_11|grid_12|grid_13|grid_14|grid_15|grid_16|grid_17/');
       }
   });
   $(old).removeClass('grid_1 grid_2 grid_3 grid_4 grid_5 grid_6 grid_7 grid_8 grid_9 grid_10 grid_11 grid_12 grid_13 grid_14 grid_15 grid_16').addClass(new_class_name);
   console.log('Old grid1 class name is ' + old_class_name + ' and New grid1 class name is ' + new_class_name);
}

I can use addClass(new_class_name); without any trouble.

I can use use removeClass('grid_8'); without any trouble (grid_8 being the actual class name)

When I use removeClass(old_class_name); it just doesn’t work. No error message, nothing in firebug, just doesn’t work.

Since I don’t know what the previous value will be, I have to remove any possible class that could be there

 $(old).removeClass('grid_1 grid_2 grid_3 grid_4 grid_5 grid_6 grid_7 grid_8 grid_9 grid_10 grid_11 grid_12 grid_13 grid_14 grid_15 grid_16').addClass(new_class_name);

That’s the only way I can get it to work. Sure it works, but seems like I’m either missing something or doing something wrong. You can see what I’m trying to do here if it would help. I just don’t see how I can add a class using a var, but not remove one the same way.

  • 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-28T20:38:45+00:00Added an answer on May 28, 2026 at 8:38 pm

    Seems your regex is wrong. Use either a string without the slashes or just the slashes.

    old_class_name = this.match(/grid_1|grid_2|grid_3|grid_4|grid_5|grid_6|grid_7|grid_8|grid_9|grid_10|grid_11|grid_12|grid_13|grid_14|grid_15|grid_16|grid_17/);
    

    or maybe even

    old_class_name = this.match(/grid_[0-9]+/);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a master page that uses 3 instances of System.Web.UI.WebControls.AdRotator each backed by
I can't play more than one sound per page. I created 2 instances of
I have created a simple audio player to play continuously even if the page
i created a page on which i tried to attain the effect of bottom
I created a page that has a JQuery based dialog using the standard JQuery
I have created a page on my site where users can post directly to
I'm displaying cars on a page created with a view and displays. I want
I created a single page (with code behind .vb) and created Public intFileID As
I've created a web page that lets you input some information and then draws
I had created one HTML page for my experiance. In this i had use

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.