Sometimes there is situation when in any tag container we have usual text and some another tag containers, and we need to remove text only from this main container living all another elements inside:
1 2 3 | jQuery('.wpbdp-field label').contents().filter(function () { return this.nodeType === 3; }).remove(); |
Example of HTML code for this task:
1 2 3 4 5 6 | <div class="wpbdp-field"> <label for=""> Any text which should be removed <span>here the content should not be touched</span> </label> </div> |
"Any text which should be removed" - will be removed from the tag <label>
