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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:45:56+00:00 2026-05-22T20:45:56+00:00

So the server is giving me a block of html within a hidden input.

  • 0

So the server is giving me a block of html within a hidden input. I need to take this block (which contains multiple divs) and move those divs, but with some logic.

My approach is to take the value of the hidden input (html block) and append it into a newly created hidden div:

  var history = $("input[name=history]").val();
  $("#global_wrapper").after("<div id='history_temp' style='display:none;'></div>");
  $("#history_temp").html(history);

Here is an example of what the HTML block looks like:

<div class="off 1"></div>
<div class="off 1"></div>
<div class="off 2"></div>
<div class="off 3"></div>

The .off will always be there and the number class will range from 1-9

Based on the number class, I need to move each of these divs into an existing html block that looks like this:

<div class="on 1"></div>
<div class="on 2"></div>
<div class="on 3"></div>

The logic is that each .off div needs to be appended after the .on div with the same number class so that the end result would look like this:

<div class="on 1"></div>
<div class="off 1"></div>
<div class="off 1"></div>
<div class="on 2"></div>
<div class="off 2"></div>
<div class="on 3"></div>
<div class="off 3"></div>

My attempt was to run an each function for each .off div and then set up an if this.hasClass for each number div, but it was duplicating the .off divs and there were like 12 .off divs when there should have been just 3. Here is my code:

   $("#history_temp .off").each(function(){
    if ($(this).hasClass("1")) {
      $(this).clone().insertAfter(".on.1");
    }
    else if ($(this).hasClass("2")) {
      $(this).clone().insertAfter(".on.2");
    }
    else if ($(this).hasClass("3")) {
      $(this).clone().insertAfter(".on.3");
    }
    else if ($(this).hasClass("4")) {
      $(this).clone().insertAfter(".on.4");
    }
    else if ($(this).hasClass("5")) {
      $(this).clone().insertAfter(".on.5");
    }
    else if ($(this).hasClass("6")) {
      $(this).clone().insertAfter(".on.6");
    }
    else if ($(this).hasClass("7")) {
      $(this).clone().insertAfter(".on.7");
    }
    else if ($(this).hasClass("8")) {
      $(this).clone().insertAfter(".on.8");
    }
    else if ($(this).hasClass("9")) {
      $(this).clone().insertAfter(".on.9");
    }
    else {
      return false;
    } 
  }); 

Could anyone point me in the right direction? I’m curious as to what the most efficient solution would be.

Thanks,
Brian

EDIT: Fixed an error in my example code (was missing the “.” before each on class)

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

    FWIW, your code works fine: http://jsfiddle.net/7XWuN/2/

    I assume there is something else going on in the code you did not post.

    Without any more context, I would suggest something like this:

    $("#history_temp .off").each(function(){
        var n = this.className.match(/\d+/)[0];
        $(this).insertAfter('.on.' + n);
    });
    

    DEMO

    This works under the assumption that the elements have only one class that contains a number. It could also be that using numbers as classes does not play well with the selector, as classes are not allowed to start with a number afaik. If it does not work, prepend some other character.

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

Sidebar

Related Questions

The server.xml which controls the startup of Apache Tomcat's servlet container contains a debug
The UPS server keeps giving me this response : HTTP/1.1 200 OK Server: Apache
I have this SQL statement and SQL Server is giving me the following error:
So our SQL Server 2000 is giving me the error, The log file for
My iphone application wants to connect to server by giving username and password. How
The following is an unexpected warning message the server is giving me: Warning: DOMDocument::loadHTML()
This code giving me fits. Returns the error: The given ColumnName 'COURSENAME' does not
SQL Server 2005 is giving me the following error during the System Check portion
This is in reference to this question here: Check Contraint Bypassing CATCH block in
I need to create some pretty big tables in SQL Server 2008. While 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.