I want to clear out the "normal text", but no glyphicon's.
The important code sections and its results:
$("#btn_test").html() will give me:
"<span class="glyphicon glyphicon-floppy-disk"
aria-hidden="true"></span> Speichern & schließen"
$("#btn_test").text() will give me:
" Speichern & schließen"
I just want to delete the text "" Speichern & schließen", without .replace(...)-function (because the text is dynamic).
I tried $("#btn_test").text(""), but this will clear also my span element.
Thank you.
Updated('possible duplicate'): Yes, it is the same question like here, but not the answer of Chris Davis, which solved my problem.
Remove the text node, e.g:
$('#btn_test').contents().filter(function(){
  return this.nodeType === 3;
}).remove();
Or simpler, if it's always the last:
$('#btn_test').contents().last().remove();
Simplest way would be to wrap your text in a span — it then becomes trivial to remove this text.
$(document).ready(function() {
	$('#btn_test .text').remove();
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="btn_test">
  <span class="glyphicon glyphicon-floppy-disk"
        aria-hidden="true"></span> 
  <span class="text">Speichern & schließen</span>
</button>jsFiddle link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With