1

I simply want to remove the text which is after input, any ideas ?

<label class="checkbox">
<input id="forms-element-0-0" name="checkbox[]" value="1" type="checkbox">
remove me
</label>
Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307
user1876234
  • 857
  • 2
  • 14
  • 28
  • 1
    What about text before it? – crush Jan 09 '14 at 21:35
  • possible duplicate of [How to remove text inside an element with jQuery?](http://stackoverflow.com/questions/6690445/how-to-remove-text-inside-an-element-with-jquery) – j08691 Jan 09 '14 at 21:37

1 Answers1

3

I'd skip jQuery for this, if it's only the one input's following-text, and use:

document.getElementById('forms-element-0-0').nextSibling.nodeValue = '';

JS Fiddle demo.

To remove the textNode (rather than simply replace its text with an empty string):

var text = document.getElementById('forms-element-0-0').nextSibling;
text.parentNode.removeChild(text);

JS Fiddle demo.

If you have a collection of label elements to work through I'd suggest:

$('label').contents().filter(function(){
    return this.nodeType === 3;
}).remove();

JS Fiddle demo.

References:

David Thomas
  • 249,100
  • 51
  • 377
  • 410