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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:58:05+00:00 2026-05-26T20:58:05+00:00

Using .each() to go through an array, and trying to use replace() to find

  • 0

Using .each() to go through an array, and trying to use replace() to find all the “<br>” and replace with ” ” (pretty simple) but nothing happens – no errors, it just doesn’t replace.

//get values of each td in row
var values = '';
var tds = $(this).find('td');

$.each(tds, function(index, tditem) {
    values = values + "td" + ':' + tditem.innerHTML + '\n';
    values = values.replace(/<br>/i, " ");
});

Acknowledging that it would be better to manipulate a DOM element (and selecting one of those answers as the correct answer) I ended up adding this to my function as it just makes my life easier in the short-term:

values = values.replace(/<br>/i, " ");

Thanks @all

  • 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-26T20:58:06+00:00Added an answer on May 26, 2026 at 8:58 pm

    You don’t need to do string processing to achieve this result. Here is the best (right) way to do that:

    $(this).find('td br').remove();
    

    The general rule is: always use the DOM to reach and manipulate the elements, avoid string analysis for this kind of operation.


    Edit:

    In case you don’t want to change the real DOM elements, just clone then to a variable like so:

    var HTML = '';
    var tds = $(this).find('td').clone();
    $(tds).find('br').remove();
    HTML = $(tds).html();
    alert(HTML);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to loop through an array of strings using the foreach control, and
Using Javascript, I'm trying to loop through an array and execute a function with
I'm using tDom to loop through some XML and pull out each element's text().
I'm using the following syntax to loop through a list collection: For Each PropertyActor
I'm generating an unordered list through javascript (using jQuery). Each listitem must receive its
I'm trying to iterate over an enum, and call a method using each of
I've been using $.each to do iterations for a while now, but I keep
I'm trying to make a loop that will recurse through an array of bytes
I was trying to use $.getJSON to go through the json arrays from the
I have an array inside an $.each function. I want to iterate through it

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.