简体   繁体   中英

How to remove span tag using jquery without using remove method?

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,'');

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();
}

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

For the second part see jods answer :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM