2

I've an HTML

<td class="abc"><b><span>NO</span>YES</b> ALL</td>

I am trying to get text of class abc without span tag. For eg. in above HTML I want only "YES ALL".

$('td.abc').text() returns NOYES ALL

$('td.abc').clone.find('span').remove().text() returns NO

Can anyone help me getting all text in above HTML except particular tag, here except tag span so that I could return "YES ALL". I want a one line solution.

2
  • 1
    I doubt that the second line returns "ALL". Assuming that .clone.find is just a typo (it should be .clone().find, it probably returns "NO", the text of the span element. Commented Oct 6, 2013 at 6:21
  • @FelixKling, thanks for pointing. I've corrected my mistake. Commented Oct 6, 2013 at 6:37

1 Answer 1

3

.clone() is a method not a property, also since you are using .find() after removing the element, you should use .end() method for getting the previous collection, i.e the td element.

var text = $('td.abc').clone().find('span').remove().end().text();

http://jsfiddle.net/keY9Q/

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I've forgot to use .end()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.