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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:41:47+00:00 2026-05-28T04:41:47+00:00

What jquery can I use to change the class that’s used in the following

  • 0

What jquery can I use to change the class that’s used in the following from indent_1 to indent_2 or indent_4 to indent_2? I know about remove class but how can I do that when the classes are names that vary?

<div class="rep_td0 indent_1" id="title_1">Menu two</div> 
or 
<div class="rep_td0 indent_4" id="title_1">Menu two</div>
  • 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-28T04:41:47+00:00Added an answer on May 28, 2026 at 4:41 am

    Since you haven’t been very specific about exactly what class you want to change to another and you’ve said you want to deal with the case where you don’t know exactly what the class is, here are some ideas:

    You can find all objects that have a class that starts with “indent_” with this selector:

    $('[className^="indent_"]')
    

    If you wanted to examine the class on each one of those objects, you could iterate over that jQuery object with .each() and decide what to do with each object or you could use removeClass() with a custom function and examine the class name and decide what to do with it.

    If you just wanted to change all indent class names to indent_2, then you could use this:

    $('[className^="indent_"]').removeClass("indent_1 indent_3 indent_4").addClass("indent_2");
    

    or, using a custom function that can examine the class name with a regex:

    $('[className^="indent_"]').removeClass(function(index, name) {
        var match = name.match(/\bindent_\d+\b/);
        if (match) {
            return(match[0]);
        } else {
            return("");
        }
    }).addClass("indent_2");
    

    Or, if all you want to do is find the object with id=”title_1″ and fix it’s classname, you can do so like this:

    var o = document.getElementById("title_1");
    o.className = o.className.replace(/\bindent_\d+\b/, "indent_2");
    

    You can see this last one work here: http://jsfiddle.net/jfriend00/tF8Lw/

    If you’re trying to make this into a function that could take different numbers, you could use this:

    function changeIndentClass(id, indentNum) {
        var item = document.getElementById(id);
        item.className = item.className(/\bindent_\d+\b/, "indent_" + indentNum);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if I can use the following JQuery function on
Is there a JSON query class or jQuery plugin that I can use to
Can I use Jquery to call an action and then change the image when
I can use the jquery .data attribute and an alert confirms that it worked,
Is there any way that I can use JavaScript (and jQuery) to create a
I know in jQuery 1.4.x there is a method delay(). We can use it
How can I use jQuery UJS to submit a form after the change event
I was creating a countdown timer using javascript; I can use jQuery. I want
Is there a plugin I can use for Queuing the animations. I see jQuery.Queue()
How I can capture browser restore/maximize event in jQuery or javascript? We can 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.