1

Consider this piece of code :

<div id="apar">
     This text is to be removed 
     <span>
         Random content
     </span>
     <span>
         Random content
     </span>
     <div>
        .....
     </div>

</div>

How could I remove "This text is to be removed" text ?

Pablo Honey
  • 1,074
  • 1
  • 10
  • 23

1 Answers1

1

Use .contents() in jquery in the context because it gets the children of each element in the set of matched elements, including text and comment nodes.

$('div').contents().first().remove();

FIDDLE

Sudharsan S
  • 15,336
  • 3
  • 31
  • 49