dan dan - 1 month ago 5
jQuery Question

delete text without element inside div after some button

here the code

<div
id="user-alert"
class="alert alert-danger col-md-offset-1 col-md-10 alert-dismissible"
role="alert"
>
<button type="button" class="close" data-hide="alert" aria-hidden="true">
<span aria-hidden="true">&times;</span>
</button>
myquestion is,, how to remove/delete this text using jquery, just this text only,,
</div>


i've tried
$('#user-alert :not(:first-child)').remove();
but it won't work

i also tried
$('#user-alert button.close).text('')
still not work

Answer

Try this UPDATED

$( "#YourIdHere" ).contents().filter(function() {
  return this.nodeType === 3;
}).remove();
Comments