1

can you please tell me how to remove the span tag using jquery. INPUT

<span class="abc">PQR </span>

OUTPUT

PQR

I done before but don't remember I think I used regex or replace .:(

Second

How to replace &nbsp by a space(" ") ?

I used like that but not work.

replace(/&nbsp;/g,'');
2
  • Why do you need to remove without using remove()? Just access the span with .text() and then remove using remove(). Commented Sep 2, 2013 at 16:11
  • I want to search a text .that why ? actually i am getting data from server having &nbsp Commented Sep 2, 2013 at 16:16

2 Answers 2

3

For the first part, Tim's answer is great. $('.abd').contents().unwrap().

For the second part, please do it properly. &nbsp; is an html-encoded special characters (non-breakable space), but there are tons of other characters you can encounter (like &eacute; for é).

Unfortunately there's no built-in standard html decode function, but you can create one with jquery like this:

function htmlDecode(encodedText) {
  return $("<div>").html(encodedText).text();
}
Sign up to request clarification or add additional context in comments.

1 Comment

not sure about that. Your fiddle is convoluted and I'm not certain to get what your problem actually is. Maybe try to simplify your fiddle to its core elements and post another question?
2

For the first part, you can use $('.abc').contents().unwrap()

For the second part see jods answer :)

3 Comments

can you use this on my searching example .First you remove all this than search
on search button click you just remove &nbsp and span tag then search jsfiddle.net/AzRcn/7
on search button click

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.