0

So let's say I have the following code:

<div id="some_id" class="another_class" style="background-color:#000;">
    Content goes here
</div>

I need some jquery that will make the code above the following:

<div>
    Content goes here
</div>

Is there any way to do that?

Ryan Saxe
  • 17,123
  • 23
  • 80
  • 128
  • 1
    Quick cheat (need to know tag name, won't work on some elements): `$('#some_id').contents().unwrap().wrap('
    ');`
    – Wesley Murch May 31 '13 at 20:52
  • @WesleyMurch should be an answer – A. Wolff May 31 '13 at 20:54
  • @roasted It's a poor answer, for reasons noted in my comment (among others). – Wesley Murch May 31 '13 at 20:55
  • @WesleyMurch it will also lose data associated with the wrapping tag, such as bound events (obviously, since you delete it and write a new one, but I think it's worth mentioning) – Lepidosteus May 31 '13 at 20:58
  • @WesleyMurch ya you are correct – A. Wolff May 31 '13 at 20:58
  • @Lepidosteus, since you are removing the id, I think it is basically a "Kill Pill"; it will be difficult to target the `div` anyway (in this case) from other `div`'s. – Sablefoste May 31 '13 at 21:00
  • @SableFoste `$e = $('#some_id'); $e.click(function(e) { /* do something */ });` If you delete the tag and rewrite it, you lose the click event. If you use the solution in the duplicate, you won't. It's "subtle" enough that someone *will* be caught by it someday (and by subtle I mean so obvious that you don't even think about it) – Lepidosteus May 31 '13 at 21:03

0 Answers0