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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:05:09+00:00 2026-05-21T12:05:09+00:00

I have this problem that i want to transfer specific ( yet not that

  • 0

I have this problem that i want to transfer specific ( yet not that specific ) classes from element to another.

this:

<span>
   <span class="THIS-something-something anotherClass"></span>
</span>

into:

<span class="THIS-something-something">
   <span class="anotherClass"></span>
</span>

Basic idea is that if you write a class in that inner span that has specific word “THIS” it would get transfered to the outer span ( the outer span is generated there with .wrap )

class with “THIS” is a class that has like.. 20 different variations ( THIS-something-something, THIS-something-anything, THIS-and-that ..and so on.. ) and “anotherClass” is totally random class and there would possibly be multiple of those as well..depending on how many i would like to insert.

I have no idea how that would go down.. Am i maybe thinking about this all wrong?

I can only make it so that all classes get copied to the outer span and then i would remove all classes from the inner span.. but that kinda defeats all purposes as it doesnt leave “anotherClass” and it copies that to the outer element…

  • 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-21T12:05:10+00:00Added an answer on May 21, 2026 at 12:05 pm

    Try this:

    $('span > span').each(function() {
        var all = $(this).attr('class').split(' ');
        for (var i = 0; i < all.length; ++i) {
            var cls = all[i];
            if (cls.indexOf('THIS-') == 0) {
                $(this).parent().addClass(cls);
                $(this).removeClass(cls);
            }
        }
    });
    

    This may have problems relating to order of processing, hence why the selector requires a span inside another span.

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

Sidebar

Related Questions

i have this problem that i can't solve for days now...here is my code.
I have this problem... I have a VS solution with these projects: Persistance, Domain,
I have this problem: My web application has a form where the users can
I have a head aching problem that I can't seem to find an easy
Ok, I have a problem. I have a set A of bottles of various
I need to transfer JavaScript Objects through JSON and transfer it's functions as well.
I want to write two simple utilities: Receives a Binary file, and converts it
I'm developing an application in C# to capture info from the serial port. The
I've made a proxy system with CURL. I do need to access the header,

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.