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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:14:55+00:00 2026-05-25T01:14:55+00:00

I have a table that has some content in it. Not all rows has

  • 0

I have a table that has some content in it. Not all rows has same content but some of them will have the first sentence as e.g.

Hello, how are you John?

Hello, how are you Mary?

Same pattern with different name.

The row will look like below. And the content in the span comes from database. Yes the text with break tags as well.

<tr style="background-color:#F7F7f7">
<td>
<span id="sp1">Hello How Are you? John <br/><br/>Some text blalablalalbal <br/><br/>"You are Awesome" <br/><br/>----What can I do for you? <br/><br/></span><br />
<span id="sp2">XYZABCD</span><br />
<span id="sp3">12345669060 Some Loren ipsum</span><br />
</td>
</tr>

I want to remove the first sentence from the rows that has Hello, how are you xyzname?.

So I have the following code that works and does what I want:

<script type="text/javascript">
        $(function () {
            $("#btnCleanUp").click(function () {
                $("table tr td").each(function () {
                    var elem = $(this).find('span:contains("Hello How Are you?")');
                    var alltxts = elem.contents().filter(function () {
                        var retm = true;
                        var str = this.nodeValue;
                        if (str != null) {
                            var bstr = str.indexOf("Hello How Are you?");
                            $(this).nodeValue = "";
                            if (bstr >= 0) {
                                retm = false;
                            }
                        }
                        var ret = (this.nodeType == 3) && retm;
                        return ret;
                    });
                    elem.text("");
                    elem.html("<br/>");
                    $(alltxts).each(function () {
                        var hm = $(this);
                        elem.html(elem.html() + hm[0].nodeValue + "<br/><br/>");
                    });
                });
            });
        });
    </script>

Here is the sample demo.

Question:

Can I do this in a better way?

I want to simplify the above code block if possible, I mean logic-wise because I think it can be done in a better way given the potential of jquery.

I am open to do this in C# if that’s a better way. Please provide sample code.

  • 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-25T01:14:56+00:00Added an answer on May 25, 2026 at 1:14 am
    $(function () {
            $("#btnCleanUp").click(function () {
                $("table tr td span").each(function () {
                    var data = $(this).html();
                    data = data.replace(/^Hello how are you\?.*?(<br ?\/?>){1,2}/i,'');
                    $(this).html(data);
    
                });
            });
        });
    

    See here for demo

    But i’m not really sure JavaScript is the best place to be doing this.

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

Sidebar

Related Questions

I have a table within my database that has many records, some records share
I have a table that has redundant data and I'm trying to identify all
hi to all i have a table that is named books and it has
I'm working on a table where all rows have at least one class. Some
I have some older (broken) code that has a join using a *= table1.ID
I have a table that has an insert trigger on it. If I insert
I have a table that has a processed_timestamp column -- if a record has
I have a table that has a primary key that's an INT... I have
I have a table that has 8 million records, with many fields, including lat/long
I have a table that has about 1/2 million records in it. Each month

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.