-2

i have this:

<div>All <span class="hl">text</span> should <span class="hl">be <span class="hl">unwrapped</span> <span>but not me</span> </span></div>

how to remove all spans (with class="h1") to get this?

<div>All text should be unwrapped <span>but not me</span></div>

ps: would consider javascript Regex or jquery solution

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
S S
  • 17
  • 1
  • 2
  • 3
    Obligatory link: http://stackoverflow.com/a/1732454/44084 – Andreas Grech Apr 04 '13 at 15:21
  • if the spans are always like this, I would consider replacing them (opening and closing) by empty string... but that's because I'm no good with regex :-) – Laurent S. Apr 04 '13 at 15:22
  • possible duplicate http://stackoverflow.com/questions/2719078/how-to-remove-only-tag-using-jquery – Dolo Apr 04 '13 at 15:26
  • 1
    I think you should really explain using words what you want. Are you now saying that the unwrapping should affect spans with a class `"h1"`? –  Apr 04 '13 at 15:32
  • 1
    Oh god! Who put negative vote for all answers?? – Dolo Apr 04 '13 at 15:37

2 Answers2

3

In jQuery:

$("span.hl").contents().unwrap();

will do what you want for that specific line of code, but you may have to use differing selectors if your code changes.

Ian
  • 50,146
  • 13
  • 101
  • 111
Ben Green
  • 428
  • 1
  • 7
  • 18
0
$('span .h1').contents().unwrap(); 

This code will do

Dolo
  • 966
  • 14
  • 28