2

I'm trying to get the html of an element except for one of its children.

I've tried this based on other questions [1][2] (etc), but the :not selected does not appear to work on my case.

See this: http://jsfiddle.net/GyKr6/1/

In this case, this works as expected

$("#previewLink .toRemove").remove();

But I want the resulting html.

What am I doing wrong?

Community
  • 1
  • 1
jose
  • 2,733
  • 4
  • 37
  • 51

1 Answers1

5
$("#previewLink").clone().find(".toRemove").remove().end().html();
Tomalak
  • 332,285
  • 67
  • 532
  • 628
  • Beautiful! Thank you. I've never used .end() before – jose Jan 08 '13 at 18:22
  • 1
    @jose `.end()` is a little bit counter-intuitive at first but it's incredibly useful. If you envision a chain of jQuery calls as a stack, `.end()` pops the last "destructive" entry off that stack and restores the previous state. "Destructive" means "every operation that changes the list of selected elements", in this case `.find()`. – Tomalak Jan 08 '13 at 18:31