I have this button, shown here as it appears when using Developer Tools on Chrome and doing an inspect:
<button type="button" class="btn" data-action-type="2">
<span class="glyphicon glyphicon-ok>
::before
</span>
" Action "
</button>
I want to change "Action" to "No Action", so I do this:
var btn = $('[data-action-type = "2"]');
btn.text('No Action');
This does change the text, but it also wipes out the span, and thus my icon. How do I change the text while keeping the icon? I tried console.log(btn) to see if I could find where "Action" is and attempt to change just that, but I couldn’t find it.
2
Answers
You want to use
If you have a static
span
in thebutton
tag you can do thisvar button = $('[data-action-type = "2"]');
button.html('<span class="glyphicon glyphicon-ok"> ::before </span> Some Text')
If you have a span but thats not static, what you can do is:
var button = $('[data-action-type = "2"]');
button.contents().last()[0].nodeValue = "Byee"