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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:15:34+00:00 2026-06-11T21:15:34+00:00

I was able to turn a long string into a dl list as shown

  • 0

I was able to turn a long string into a dl list as shown below:

 <div class="classA">
   <dl id="idA"> Display # 252215425:  </dl>
   <dl id="idB">3 Apples   </dl>
   <dl id="idC">3 Peaches   </dl>
   <dl id="idD">10 Seadless Watermelons   </dl>
   <dl id="idE">23 Bananas </dl>
 </div>

The result I want is:

 <div class="classA">
   <dl id="idA"> 
       <dd>252215425</dd>
       <dt>Display #</dt>
   </dl>

   <dl id="idB"> 
       <dd>3</dd>
       <dt>Apples</dt>
   </dl>

   <dl id="idC"> 
       <dd>3</dd>
       <dt>Peaches</dt>
   </dl>

   <dl id="idD"> 
       <dd>10</dd>
       <dt>Seadless Watermelons</dt>
   </dl>

   <dl id="idE"> 
       <dd>23</dd>
       <dt>Bananas</dt>
   </dl>
 </div>

The goal I am trying to achieve:
1. split each dl content into an array
2. find numbers and save them in “n”
3. find text and save them in “w”
4. wrap “n” with ‘dd’ tag
5. wrap “w” with ‘dt’ tag
6. the “n” & “w” should NOT have leading & trailing white spaces

Here is the code I came up, but it didn’t work…

$("div.classA dl").each(function(){
      var a = $("div.classA dl").html();
      a = a.split(' ');
      var n = a.match(/d+/);
      var w = a.match(/D+/);
      $("div.classA dl").text('');
      $("div.classA dl").append('<dd>'n'</dd>');
      $("div.classA dl").append('<dt>'w'</dt>');

});
  • 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-06-11T21:15:35+00:00Added an answer on June 11, 2026 at 9:15 pm

    That’s pretty much it, but you have a couple of small issues in your code:

    1. To match a digit, use \d instead of just d. Same goes with D, where it should be \D;
    2. match returns an array, thus you need to access the first position of it to obtain the matched value;
    3. $.each already iterates over all dls, no need to select them all again in each iteration of the loop. Just refer to the element that is being iterated, using this.

    Here’s the fixed code and a DEMO:

    $("div.classA dl").each(function() {
      var $this = $(this);
      var text = $this.text();        
      var n = text.match(/\d+/)[0];
      var w = text.match(/\D+/)[0].replace(/^\s*|\s*$/g, '');
    
      $this.empty();
    
      $("<dd>").text(n).appendTo($this);
      $("<dt>").text(w).appendTo($this);
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to turn a flat xml data sets into html
I need to be able to turn pinch-zoom on and off using the viewport
I've been trying to work on a project to he able to turn loop
how can i turn my listbox to resort able by dragging and dropping in
I'd like users to be able to reconfigure their installation (turn components on/off) by
Not able to store all binary data values into sqlite3 table using QT. For
I need to be able to access a list throughout my Rails project. For
I am thinking about converting a PDF document into a long scrolling HTML doc
Is it possible to display a multiline string in a Flex DataGridColumn? i.e. Display:
I want to be able to turn off overscroll (the glowing effect when reaching

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.