So, I'm pretty dead end on how to exclude child children from selected in jQuery ...
Here is my HTML structure in my line:
<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 did not select this. I am trying to parse the text โText I want to extract hereโ from this structure, which comes from some arbitrary XML feed.
Here is my test jQuery: (d is an HTML string)
$('tr > td:eq(1) > table', d).remove(); var c = $('tr > td:eq(1)', d).text();
The first row does not delete the table. I am testing a selector and it manages to select an element. Am I using the wrong method to remove an item?
I 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 only extract text inside this particular td.
source share