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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:12:12+00:00 2026-05-29T18:12:12+00:00

I had some help and some suggestions on how to remove a class name.

  • 0

I had some help and some suggestions on how to remove a class name.

Previous answer

These worked in fiddle but my application is just a bit different. I have the following:

<span id="refType_1" class="refType indent_02">Link Header</span>

My javascript looks like this:

if (action == "Edit") {
   var parent = linkObj.closest("tr");
   parent.find(".refType").html($("#Type :selected").text());  // 1
   parent.find(".refType").className.replace(/indent_\d+($|\s)/, "xxx"); 
   parent.find(".refType").trim(this.className.replace(/(^|\s)indent_\d+($|\s)/, " "));

I tried the last two ways of replacing the class name with “” but both give me an error. For example the last method gives the following:

SCRIPT438: Object doesn't support property or method 'trim'

I think I’m 99% towards getting it working but would appreciate advice. I tried a few different ways so far and it still does not work.

Please note the line with comment // 1 does work. I can change the contents of the span as needed. What does not work is:

parent.find(".refType").className.replace(/indent_\d+($|\s)/, "xxx");   or
parent.find(".refType").trim(this.className.replace(/(^|\s)indent_\d+($|\s)/, " "));

These are my two different attempts to get the text indent_xx to be removed from the span.

  • 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-29T18:12:14+00:00Added an answer on May 29, 2026 at 6:12 pm

    You did not implement the code from the previous answer correctly.

    You cannot do either of these because .className is a property of a DOM object, not of a jQuery object and you aren’t even assigning the result of the .replace() to anything:

    parent.find(".refType").className.replace(/indent_\d+($|\s)/, "xxx"); 
    parent.find(".refType").trim(this.className.replace(/(^|\s)indent_\d+($|\s)/, " "));
    

    If you following the design pattern from the previous answer, you would use this:

    parent.find(".refType").each(function() {
        this.className = $.trim(this.className.replace(/(^|\s)indent_\d+($|\s)/, " ")); 
    }); 
    

    If you know there are no other classes on those objects that you want to keep except the .refType, you can do it even simpler:

    parent.find(".refType").attr("class", "refType");
    

    This just sets the entire class name to “refType”, eliminating any other classes that might have been there.

    You could also make a jQuery plug-in that you would put somewhere in your initialization code:

    $.fn.removeIndentClasses = function() {
        this.each(function() {
            this.className = $.trim(this.className.replace(/(^|\s)indent_\d+($|\s)/, " ")); 
        });
        return this;
    }
    

    Then, your code would just be this:

    parent.find(".refType").removeIndentClasses();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help with this problem in implementing with XSLT, I had already implemented
I had some code that ran commands through Runtime.getRuntime.exec(String) , and it worked on
I had some decryption code (using wincrypt.h ) that lived within my FileReader.cpp class.
I had some troubles implementing Lawler's algorithm but thanks to SO and a bounty
I'm looking for some help/suggestions for backing up two large databases to one server
( First time programming in PHP. Had some help. Need a bit more. )
I had some time this afternoon to run a head to head comparison between
I had some site templates designed for me recently. I got the final HTML
I had some problems with my subversion server and i had to restore it
I had some questions regarding the structure and behavior of a model, using UML,

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.