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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:37:26+00:00 2026-06-04T15:37:26+00:00

in my function in a jquery, i try to split a long string. i

  • 0

in my function in a jquery, i try to split a long string. i think that when splitting, the result is an array. so i used .each to get the values of splitted string. however, it is not showing anything. where is my error in this syntax:

 function DisplayList(data) {
    $.each(data.split('|'), function (index, value) {
        $(".listDisplay").html('<p>' + value + '</p>');
    });
 };  

when i put index in the .html() instead of value, i am shown the number of elements in the array. it’s supposed to show something like [0], [1], [2]… right?

what i really want is to show in a paragraph form the contents of my splitted string… (.listDisplay is a 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-06-04T15:37:27+00:00Added an answer on June 4, 2026 at 3:37 pm

    The line:

    $(".listDisplay").html('<p>' + value + '</p>');
    

    overwrites the contents of “.listDisplay” with the current value. So each iteration of the $.each() overwrites the previous value and then when the $.each() finishes “.listDisplay” will hold whatever value was from the final iteration.

    Try changing it to:

    $(".listDisplay").append('<p>' + value + '</p>');
    

    That will add a new paragraph to the end of “.listDisplay” rather than overwriting the existing contents. So the .each() will add a new paragraph for each item in the array returned by data.split('|').

    (You may want to add $(".listDisplay").empty() or $(".listDisplay").html("") just before the $.each() to clear any existing contents in your div before adding the new paragraphs.)

    Another approach is to do it in one line without the $.each():

    function DisplayList(data) {
       $(".listDisplay").html('<p>' + data.replace(/\|/g, '</p><p>') + '</p>');
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my relevant jQuery code: $.get('sampleData.csv', function(data) { var lines = data.split('\r\n'); The
I thought I could split a string inside a jquery function using the JavaScript
I tried to do this: try{ (function($){ ... my plugin stuff })(jQuery); }catch(er){ alert(an
jQuery(.single_writing).each(function(){ jQuery(this).click(function(){ jQuery(#thisTickets).val(); jQuery(#my_iframe).contents().find('.ticket_id').each(function(){ jQuery(this).click(function(){ if (jQuery(this).attr(checked)==true){ jQuery(#thisTickets).val(jQuery(#thisTickets).val()+jQuery(this).attr(id)+, ); } }); }); }) });
I have a problem with a load function in jquery i try to call
Ok, so here's the skinny... I've worked out a jQuery function that will first
I have a trouble with jquery each. this each block; $(document).ready( function(){ $('td.trh').each(function(index) {
I'm using the .remove() function from within jQuery to try and remove a form
I have function that opens up a window, and the values from the newly
I try to make a recursive function to delete files using jQuery and ajax

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.