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

The Archive Base Latest Questions

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

So, I am pretty stumped as to how to exclude a sub children from

  • 0

So, I am pretty stumped as to how to exclude a sub children from getting selected in JQuery…

Here is my HTML structure in my string:

<table>
   <tr>
       <td>some data I don't want.</td>
       <td>
       <table><tr><td>more data I don't want</td></tr></table>
       Text I want to extract here.
       </td>
   </tr>
</table>

Note: I didn’t choose this. I am trying to parse the text “Text I want to extract here” out of this structure that comes from some arbitrary xml feed.

Here is my test JQuery: (d is the HTML string)

$('tr > td:eq(1) > table', d).remove();
var c = $('tr > td:eq(1)', d).text();

The first line does not remove the table. I test the selector and it does manage to select the element. Am I using the wrong method to remove the element?

I had also tried using not() and replaceWith() with no luck.

$('tr > td:eq(1)', d).not('tr > td:eq(1) > table').text();

and

$('tr > td:eq(1) > table', d).replaceWith("");

I am open to other selection methods that will retrieve only the text within that specific td.

  • 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-27T05:14:55+00:00Added an answer on May 27, 2026 at 5:14 am

    You state that “d is the HTML string”.

    This means that when you do this:

    $('tr > td:eq(1) > table', d).remove();
    var c = $('tr > td:eq(1)', d).text();
    

    …you’re creating elements from the same unmodified string twice.


    You need to create elements out of it once, then cache those elements.

    var $d = $(d);  // create the elements out of the string, and cache the set
    
    $d.find('tr > td:eq(1) > table').remove();  // remove table from the cached set
    var c = $d.find('tr > td:eq(1)').text(); // target the <td> and get its text
    

    JSFIDDLE DEMO


    Or, because of jQuery’s .end() method, you could do it all in one shot like this:

    var c = $(d).find('tr > td:eq(1)')
                .children('table')
                .remove()
                .end()
                .text();
    

    JSFIDDLE DEMO

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

Sidebar

Related Questions

I have an issue that has got me pretty stumped, and would appreciate some
Stumped here. Posted a similar question before. We have a pretty large WPF app
I'm pretty stumped here. I have 2 tables and I'm left joining the first
I'm pretty stumped here... I've got what I believe to be a really simple
I'm stumped by some of the behavior of the Select-Object cmdlet. Here is an
This is a pretty simple question but I'm somewhat stumped. I am capturing sections
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
Pretty simple question. I've got some Polygons and GroundOverlays defined in KML. Is there
I'd consider myself an advanced web developer but I'm pretty stumped as to what
I'm stumped on how namespaced custom events are supposed to work in jQuery. 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.